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):
N,M,K=map(int,input().split())
par=[i for i in range(N+1)]
siz=[1 for i in range(N+1)]
fre=[0 for i in range(N+1)]
blo=[0 for i in range(N+1)]
rank=[0 for i in range(N+1)]

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


def union(a,b):
    a=find(a)
    b=find(b)
    if(a==b):
        return 0
    else:
        par[a]=b
        siz[b]+=siz[a]

def size(a):
    return siz[find(a)]

def same(a,b):
    return find(a)==find(b)

for i in range(M):
    A,B=map(int,input().split())
    union(A,B)
    fre[A]+=1
    fre[B]+=1
for i in range(K):
    C,D=map(int,input().split())
    if(same(C,D)):
        blo[C]+=1
        blo[D]+=1

for i in range(1,N+1):
    print(size(i)-fre[i]-blo[i]-1,end=' ')

N,M,K=map(int,input().split())
par=[i for i in range(N+10)]
siz=[1 for i in range(N+10)]
fre=[0 for i in range(N+10)]
blo=[0 for i in range(N+10)]
rank=[0 for i in range(N+10)]

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


def union(a,b):
    a=find(a)
    b=find(b)
    if(a==b):
        return 0
    else:
        par[a]=b
        siz[b]+=siz[a]

def size(a):
    return siz[find(a)]

def same(a,b):
    return find(a)==find(b)

for i in range(M):
    A,B=map(int,input().split())
    union(A,B)
    fre[A]+=1
    fre[B]+=1
for i in range(K):
    C,D=map(int,input().split())
    if(same(C,D)):
        blo[C]+=1
        blo[D]+=1

for i in range(1,N+1):
    print(size(i)-fre[i]-blo[i]-1,end=' ')

N,M,K=map(int,input().split())
par=[i for i in range(N)]
siz=[1 for _ in range(N)]
rank=[0 for _ in range(N)]

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

def union(a,b):
    a=find(a)
    b=find(b)
    if(a==b):
        return 0
    else:
        if rank[a]>rank[b]:
            par[b]=a
            siz[a]+=siz[b]
        else:
            par[a]=b
            siz[b]+=siz[a]
            if rank[a]==rank[b]:
                rank[b]+=1
            

def size(a):
    return siz[find(a)]

def same(a,b):
    return find(a)==find(b)

ans=[0 for i in range(N)]
for _ in range(M):
    A,B=map(int,input().split())
    A,B=A-1,B-1
    union(A,B)
    ans[A]-=1
    ans[B]-=1
for i in range(N):
    ans[i]+=size(i)-1
for _ in range(K):
    C,D=map(int,input().split())
    C,D=C-1,D-1
    if(same(C,D)):
        ans[C]-=1
        ans[D]-=1
        
print(*ans)

Verdicts: Runtime Error

Runtime Error

Accepted