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.n=n
        self.parents=[-1]*n

    def find(self,a):
        if self.parents[a]<0:
            return a
        else:
            self.parents[a]=self.find(self.parents[a])
            return self.parents[a]


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

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

    def same(self,x,y):
        if self.find(x)==self.find(y):
            return True
        else:
            return False
          
N,M,K=map(int,input().split())
uf=Unionfind(N)
friend=[list(map(int,input().split())) for i in range(M)]
block=[list(map(int,input().split())) for i in range(K)]
ff=[[] for i in range(N)]
bb=[[] for i in range(N)]
ans=[]
for i in range(M):
    uf.union(friend[i][0]-1,friend[i][1]-1)
    ff[friend[i][0]-1].append(friend[i][1]-1)
    ff[friend[i][1]-1].append(friend[i][0]-1)
for i in range(K):
    bb[block[i][0]-1].append(block[i][1]-1)
    bb[block[i][1]-1].append(block[i][0]-1)
for i in range(N):
    ans.append(uf.size(i)-1-(len(ff[i])))
    for j in bb[i]:
        if uf.same(j,i)==True:
            ans[i]-=1
print(ans)



class Unionfind():

    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n

    def find(self,a):
        if self.parents[a]<0:
            return a
        else:
            self.parents[a]=self.find(self.parents[a])
            return self.parents[a]


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

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

    def same(self,x,y):
        if self.find(x)==self.find(y):
            return True
        else:
            return False
          
N,M,K=map(int,input().split())
uf=Unionfind(N)
friend=[list(map(int,input().split())) for i in range(M)]
block=[list(map(int,input().split())) for i in range(K)]
ff=[[] for i in range(N)]
bb=[[] for i in range(N)]
ans=[]
for i in range(M):
    uf.union(friend[i][0]-1,friend[i][1]-1)
    ff[friend[i][0]-1].append(friend[i][1]-1)
    ff[friend[i][1]-1].append(friend[i][0]-1)
for i in range(K):
    bb[block[i][0]-1].append(block[i][1]-1)
    bb[block[i][1]-1].append(block[i][0]-1)
for i in range(N):
    ans.append(uf.size(i)-1-(len(ff[i])))
    for j in bb[i]:
        if uf.same(j,i)==True:
            ans[i]-=1
answer=[str(ans[i]) for i in range(len(ans))]
print(" ".join(answer))

Verdicts: Wrong Answer

Accepted