Buggy python submission (verdict: Runtime Error):
# D - Friend Suggestions

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

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

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def same(self, x, y):
        return self.root(x) == self.root(y)

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

N,M,K = map(int,input().split())
friend = UnionFind(N+1)
block = [1]*(N+1)
for _ in range(M):
    x,y = map(int,input().split())
    block[x] += 1
    block[y] += 1
    friend.union(x,y)
for _ in range(K):
    x,y = map(int,input().split())
    if friend.same(x,y):
        block[x] += 1
        block[y] += 1
ans = [friend.size(i)-block[i] for i in range(1,N+1)]
print(*ans)

Fixed submission:
# D - Friend Suggestions

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

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

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def same(self, x, y):
        return self.root(x) == self.root(y)

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

N,M,K = map(int,input().split())
friend = UnionFind(N+1)
block = [1]*(N+1)
for _ in range(M):
    x,y = map(int,input().split())
    block[x] += 1
    block[y] += 1
    friend.union(x,y)
for _ in range(K):
    x,y = map(int,input().split())
    if friend.same(x,y):
        block[x] += 1
        block[y] += 1
ans = [friend.size(i)-block[i] for i in range(1,N+1)]
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Friend Suggestions
from collections import deque
N,M,K = map(int,input().split())
friend = [set() for _ in range(N+1)]
block = [{i} for i in range(N+1)]
for _ in range(M):
    x,y = map(int,input().split())
    friend[x].add(y)
    friend[y].add(x)
for _ in range(K):
    x,y = map(int,input().split())
    block[x].add(y)
    block[y].add(x)
connect = [{i} for i in range(N+1)]
check = [0]*(N+1)
for i in range(1,N+1):
    if check[i]!=0:
        continue
    que = deque([i])
    con = {i}
    while len(que)>0:
        j = que.popleft()
        for x in friend[j]:
            if x not in con:
                que.append(x)
                con.add(x)
    for x in con:
        connect[x] = set(con)
        check[x] = 1
ans = [len(connect[i].difference(friend[i],block[i])) for i in range(1,N+1)]
print(*ans)

Fixed submission:
# D - Friend Suggestions

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

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

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def same(self, x, y):
        return self.root(x) == self.root(y)

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

N,M,K = map(int,input().split())
friend = UnionFind(N+1)
block = [1]*(N+1)
for _ in range(M):
    x,y = map(int,input().split())
    block[x] += 1
    block[y] += 1
    friend.union(x,y)
for _ in range(K):
    x,y = map(int,input().split())
    if friend.same(x,y):
        block[x] += 1
        block[y] += 1
ans = [friend.size(i)-block[i] for i in range(1,N+1)]
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Friend Suggestions
from collections import deque
N,M,K = map(int,input().split())
friend = [set() for _ in range(N+1)]
block = [{i} for i in range(N+1)]
for _ in range(M):
    x,y = map(int,input().split())
    friend[x].add(y)
    friend[y].add(x)
for _ in range(K):
    x,y = map(int,input().split())
    block[x].add(y)
    block[y].add(x)
connect = [{i} for i in range(N+1)]
for i in range(1,N+1):
    if connect[i]!={i}:
        continue
    que = deque([i])
    con = {i}
    while len(que)>0:
        j = que.popleft()
        for x in friend[j]:
            if x not in con:
                que.append(x)
                con.add(x)
    for x in con:
        connect[x] = set(con)
ans = [len(connect[i].difference(friend[i],block[i])) for i in range(1,N+1)]
print(*ans)

Fixed submission:
# D - Friend Suggestions

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

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

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def same(self, x, y):
        return self.root(x) == self.root(y)

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

N,M,K = map(int,input().split())
friend = UnionFind(N+1)
block = [1]*(N+1)
for _ in range(M):
    x,y = map(int,input().split())
    block[x] += 1
    block[y] += 1
    friend.union(x,y)
for _ in range(K):
    x,y = map(int,input().split())
    if friend.same(x,y):
        block[x] += 1
        block[y] += 1
ans = [friend.size(i)-block[i] for i in range(1,N+1)]
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Friend Suggestions
N,M,K = map(int,input().split())
friend = [set() for _ in range(N+1)]
block = [set() for _ in range(N+1)]
friendly = [{i} for i in range(N+1)]
for _ in range(M):
    x,y = map(int,input().split())
    friend[x].add(y)
    friend[y].add(x)
    if y not in friendly[x]:
        friendly[x].add(y)
        friendly[y].add(x)
    friend_x = set(friendly[x])
    friend_y = set(friendly[y])
    for w in friend_x:
        friendly[w].add(y)
        for z in friend_y:
            friendly[w].add(z)
    for w in friend_y:
        friendly[w].add(x)
        for z in friend_x:
            friendly[w].add(z)
for _ in range(K):
    x,y = map(int,input().split())
    block[x].add(y)
    block[y].add(x)
ans = []
for i in range(1,N+1):
    tmp = []
    for x in friendly[i]:
        if x!=i and x not in friend[i] and x not in block[i]:
            tmp.append(x)
    ans.append(len(tmp))
print(*ans)

Fixed submission:
# D - Friend Suggestions

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

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

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def same(self, x, y):
        return self.root(x) == self.root(y)

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

N,M,K = map(int,input().split())
friend = UnionFind(N+1)
block = [1]*(N+1)
for _ in range(M):
    x,y = map(int,input().split())
    block[x] += 1
    block[y] += 1
    friend.union(x,y)
for _ in range(K):
    x,y = map(int,input().split())
    if friend.same(x,y):
        block[x] += 1
        block[y] += 1
ans = [friend.size(i)-block[i] for i in range(1,N+1)]
print(*ans)