Problem p02762 (python)

Fixed submission:
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)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
par=[i for i in range(N)]
siz=[1 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:
        par[a]=b
        siz[b]+=siz[a]

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)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
par=[i for i in range(N)]
siz=[1 for i in range(N)]
fri=[0 for i in range(N)]
blo=[0 for i 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:
        par[a]=b
        siz[b]+=siz[a]

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

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

ans=[0 for i in range(N)]
for i 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 i 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)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
par=[i for i in range(N)]
siz=[1 for i in range(N)]
fri=[0 for i in range(N)]
blo=[0 for i in range(N)]
rank=[0 for i 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:
        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())
    A,B=A-1,B-1
    union(A,B)
    fri[A]+=1
    fri[B]+=1
for i in range(K):
    C,D=map(int,input().split())
    C,D=C-1,D-1
    if(same(C,D)):
        blo[C]+=1
        blo[D]+=1

ans=[size(i)-fri[i]-blo[i]-1 for i in range(N)]
print(*ans)

Buggy submission (verdict: Runtime Error):
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=' ')

Buggy submission (verdict: Runtime Error):
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=' ')