Problem: An SNS has N users - User 1, User 2, \cdots, User N.  Between these N users, there are some relationships - M _friendships_ and K _blockships_.  For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i.  For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i.  We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied:    * a \neq b.   * There is not a friendship between User a and User b.   * There is not a blockship between User a and User b.   * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1.  For each user i = 1, 2, ... N, how many friend candidates does it have?

Submission attempts (in order):
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


n, m, k = list(map(int, input().split()))
a = [0]*(m+1)
b = [0]*(m+1)
c = [0]*(k+1)
d = [0]*(k+1)
union_find = UnionFind(n)
num_friends = [-1]*(n+1)
for i in range(m):
    a[i], b[i] = map(int, input().split())
    num_friends[a[i]] += 1
    num_friends[b[i]] += 1
    union_find.union(a[i], b[i])
for i in range(k):
    c[i], d[i] = map(int, input().split())




#     frinds_mat[a[i]-1, b[i]-1] = 1
#     frinds_mat[b[i]-1, a[i]-1] = 1

num_suggest_friend = num_friends
for i in range(1, n+1):
    # num_suggest_friend[i] -= num_friends[i]
    for j in range(1, n+1):
        if (union_find.same_check(i, j)):
            num_suggest_friend[i] += 1
# print(*num_suggest_friend[1:], sep=' ')



    # print(*num_suggest_friend[1:], sep=' ')
for c_, d_ in zip(c, d):
    if union_find.same_check(c_, d_):
        num_suggest_friend[c_] -= 1
        num_suggest_friend[d_] -= 1

print(*num_suggest_friend[1:], sep=' ')


class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n+1))
        self.rank = [0] * (n+1)
        self.size = [1]*(n+1)

    
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        else:
            if self.size[x] < self.size[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]

    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def cnt(self, x):
        
        return self.size[self.find(x)]


n, m, k = list(map(int, input().split()))

union_find = UnionFind(n)
num_friends = [0]*(n+1)
num_block = [0]*(n+1)
for i in range(m):
    a, b = map(int, input().split())
    num_friends[a] += 1
    num_friends[b] += 1
    union_find.union(a, b)
# cd = [[_c, _d] for (_c, _d) in map(int, input().split())]
for i in range(k):
    # c[i], d[i] = map(int, input().split())
    c, d = map(int, input().split())
    if union_find.same_check(c, d):
        num_block[c] += 1
        num_block[d] += 1


num_suggest_friend = [0]*(n+1)  

for i in range(1, n+1):
    num_suggest_friend[i] = union_find.cnt(i) - \
        num_friends[i] - num_block[i] - 1

print(*num_suggest_friend[1:], sep=' ')


Verdicts: Wrong Answer

Accepted