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,size): 
        self.table = [-1 for _ in range(size)]
        self.cou = [1 for _ in range(size)]
    def find(self,x): 
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    def union(self,x,y): 
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] > self.table[s2]:
                self.table[s1] = s2
                self.cou[s2] += self.cou[s1]
                self.cou[s1] = 0
            elif self.table[s2] > self.table[s1]:
                self.table[s2] = s1
                self.cou[s1] += self.cou[s2]
                self.cou[s2] = 0
            else:
                self.table[s2] = s1
                self.table[s1] -= 1
                self.cou[s1] += self.cou[s2]
                self.cou[s2] = 0
        return
    
n, m, k = map(int, input().split())
BList = [[] for _ in range(n)]
friendU = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    BList[a-1].append(b-1)
    BList[b-1].append(a-1)
    friendU.union(a-1, b-1)

for i in range(k):
    c, d = map(int, input().split())
    if friendU.find(c-1) != friendU.find(d-1):
        BList[c-1].append(d-1)
        BList[d-1].append(c-1)
    
ansl = []
for i in range(n):
    j = friendU.find(i)
    ans = friendU.cou[j] - len(BList[i]) - 1
    ansl.append(ans)

print(*ansl)

class UnionFind():
    
    def __init__(self,size): 
        self.table = [-1 for _ in range(size)]
        self.cou = [1 for _ in range(size)]
        
    def find(self,x): 
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
        
    def union(self,x,y): 
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] > self.table[s2]:
                self.table[s1] = s2
                self.cou[s2] += self.cou[s1]
                self.cou[s1] = 0
            elif self.table[s2] > self.table[s1]:
                self.table[s2] = s1
                self.cou[s1] += self.cou[s2]
                self.cou[s2] = 0
            else:
                self.table[s2] = s1
                self.table[s1] -= 1
                self.cou[s1] += self.cou[s2]
                self.cou[s2] = 0
        return
    
n, m, k = map(int, input().split())
BList = [[] for _ in range(n)]
friendU = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    BList[a-1].append(b-1)
    BList[b-1].append(a-1)
    friendU.union(a-1, b-1)

for i in range(k):
    c, d = map(int, input().split())
    if friendU.find(c-1) == friendU.find(d-1):
        BList[c-1].append(d-1)
        BList[d-1].append(c-1)
    
ansl = []
for i in range(n):
    j = friendU.find(i)
    ans = friendU.cou[j] - len(BList[i]) - 1
    ansl.append(ans)

print(*ansl)

Verdicts: Wrong Answer

Accepted