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())
a=[0]*M
b=[0]*M
c=[0]*K
d=[0]*K

for i in range(M):
    a[i], b[i] = map(int, input().split())
for i in range(K):
    c[i], d[i] = map(int, input().split())
l=[-1]*(N+1)
la=N

for i in range(M):
    if l[a[i]]<0 and l[b[i]]<0:
        l[a[i]]=la
        l[b[i]]=la
        la-=1
    elif l[a[i]]>l[b[i]]:
        if l[b[i]]>0:
            l=[x if x is not l[b[i]] else l[a[i]] for x in l ]
        else:
            l[b[i]]=l[a[i]]

    else:
        if l[a[i]] > 0:
            l = [x if x is not l[a[i]] else l[b[i]] for x in l]
        else:
            l[a[i]]=l[b[i]]

t=[]

for i in range(1,N+1):

    if l[i]>0:
        p=l.count(l[i])-1
        indexes = [j for j, x in enumerate(a) if x == i]
        for j in range(len(indexes)):
            if l[b[indexes[j]]]==l[i]:
                p-=1
        indexes = [j for j, x in enumerate(b) if x == i]
        for j in range(len(indexes)):
            if l[a[indexes[j]]] == l[i]:
                p -= 1
        indexes = [j for j, x in enumerate(d) if x == i]
        for j in range(len(indexes)):
            if l[c[indexes[j]]] == l[i]:
                p -= 1
        indexes = [j for j, x in enumerate(c) if x == i]
        for j in range(len(indexes)):
            if l[d[indexes[j]]] == l[i]:
                p -= 1


    else:
        p=0
    t.append(p)
print(t)


N, M ,K= map(int, input().split())
a=[0]*M
b=[0]*M
c=[0]*K
d=[0]*K

for i in range(M):
    a[i], b[i] = map(int, input().split())
for i in range(K):
    c[i], d[i] = map(int, input().split())

l=list(range(N+1))
r=[0]*(N+1)
size=[1]*(N+1)
la=N
di=[[]for _ in range(N+1)]
def find(x):
    if l[x]==x:
        return x
    else:
        return find(l[x])

def union(x,y):
    X=find(x)
    Y=find(y)
    if r[X]>r[Y]:
        l[Y]=l[X]
        size[X]+=size[Y]
    else:
        l[X]=l[Y]

        if r[X]==r[Y]:
            r[Y]+=1
        if X!=Y:
            size[Y] += size[X]
for i in range(M):
    union(a[i],b[i])
    di[a[i]].append(b[i])
    di[b[i]].append(a[i])
for i in range(K):
    if (find(c[i])==find(d[i])):
        di[c[i]].append(d[i])
        di[d[i]].append(c[i])

t=[]
for i in range(N+1):
    p=size[find(i)]-1-len(di[i])

    t.append(p)


print(" ".join(map(str, t[1:])))


Verdicts: Wrong Answer

Accepted