Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush
from collections import Counter

N, M, K = list(map(int, input().split()))
G = [[] for _ in range(N)]
deg = [0 for _ in range(N)]
reds = [[] for _ in range(N)]

for _ in range(M):
    _a, _b = list(map(int, input().split()))
    _a -= 1
    _b -= 1
    G[_a].append(_b)
    G[_b].append(_a)
    deg[_a] += 1
    deg[_b] += 1

for _ in range(K):
    _c, _d = list(map(int, input().split()))
    _c -= 1
    _d -= 1
    reds[_c].append(_d)
    reds[_d].append(_c)


# compute connected components
numbers = {i: None for i in range(N)}

def dfs():
    visited = [False for _ in range(N)]
    stack = []
    for i in range(N):
        if not visited[i]:
            stack.append(i)
            while len(stack) > 0:
                v = stack.pop()
                visited[v] = True
                numbers[v] = i
                for neighbor in G[v]:
                    if not visited[neighbor]:
                        stack.append(neighbor)
dfs()

counter = {}
groups = {}
for i in range(N):
    if numbers[i] not in counter:
        counter[numbers[i]] = 1
        groups[numbers[i]] = set({i})
    else:
        counter[numbers[i]] += 1
        groups[numbers[i]].add(i)


for i in range(N):
    v = counter[numbers[i]] - 1
    for c in groups[numbers[i]]:
        if c in G[i] or c in reds[i]:
            v -= 1
    print(v, end='')
    if i < N - 1:
        print(" ", end='')
print()

Fixed submission:
from heapq import heappop, heappush
from collections import Counter


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

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

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return 
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
    
    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]


N, M, K = list(map(int, input().split()))
edges1 = [[] for _ in range(N + 1)]
edges2 = [[] for _ in range(N + 1)]
uf = UnionFind(N)

A, B = [], []
C, D = [], []
for _ in range(M):
    _a, _b = list(map(int, input().split()))
    A.append(_a)
    B.append(_b)
    uf.unite(_a, _b)
    edges1[_a].append(_b)
    edges1[_b].append(_a)

for _ in range(K):
    _c, _d = list(map(int, input().split()))
    C.append(_c)
    D.append(_d)
    edges2[_c].append(_d)
    edges2[_d].append(_c)

i, blocked = 1, 0
for b in edges2[1]:
    if uf.is_same_group(i, b):
        blocked += 1
print(uf.count(i) - 1 - len(edges1[i]) - blocked, end='')

for i in range(2, N + 1):
    print(' ', end='')
    blocked = 0
    for b in edges2[i]:
        if uf.is_same_group(i, b):
            blocked += 1
    print(uf.count(i) - 1 - len(edges1[i]) - blocked, end='')
print()

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush
from collections import Counter

N, M, K = list(map(int, input().split()))
edges1 = [[] for _ in range(N + 1)]
edges2 = [[] for _ in range(N + 1)]


A, B = [], []
C, D = [], []
for _ in range(M):
    _a, _b = list(map(int, input().split()))
    A.append(_a)
    B.append(_b)
    edges1[_a].append(_b)
    edges1[_b].append(_a)

for _ in range(K):
    _c, _d = list(map(int, input().split()))
    C.append(_c)
    D.append(_d)
    edges2[_c].append(_d)
    edges2[_d].append(_c)

# print(edges1)
# print(edges2)

def dfs(v):
    visited = [False for _ in range(N + 1)]
    queue = []
    heappush(queue, v)
    visited[v] = True

    counter = 0

    while queue:
        n = heappop(queue)
        for u in edges1[n]:
            if not visited[u]:
                visited[u] = True
                if u not in edges1[v] and u not in edges2[v]:
                    counter += 1
                heappush(queue, u)
    return counter


# all search
ans = []
for v in range(1, N + 1):
    counter = dfs(v)
    ans.append(counter)
print(" ".join(map(str, ans)))

Fixed submission:
from heapq import heappop, heappush
from collections import Counter


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

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

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return 
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
    
    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]


N, M, K = list(map(int, input().split()))
edges1 = [[] for _ in range(N + 1)]
edges2 = [[] for _ in range(N + 1)]
uf = UnionFind(N)

A, B = [], []
C, D = [], []
for _ in range(M):
    _a, _b = list(map(int, input().split()))
    A.append(_a)
    B.append(_b)
    uf.unite(_a, _b)
    edges1[_a].append(_b)
    edges1[_b].append(_a)

for _ in range(K):
    _c, _d = list(map(int, input().split()))
    C.append(_c)
    D.append(_d)
    edges2[_c].append(_d)
    edges2[_d].append(_c)

i, blocked = 1, 0
for b in edges2[1]:
    if uf.is_same_group(i, b):
        blocked += 1
print(uf.count(i) - 1 - len(edges1[i]) - blocked, end='')

for i in range(2, N + 1):
    print(' ', end='')
    blocked = 0
    for b in edges2[i]:
        if uf.is_same_group(i, b):
            blocked += 1
    print(uf.count(i) - 1 - len(edges1[i]) - blocked, end='')
print()