Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n, m, k = map(int, input().split())
f = [set() for _ in range(n)]
l = [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    f[a].add(b)
    f[b].add(a)
for _ in range(k):
    c, d = map(int, input().split())
    c, d = c-1, d-1
    l[d].add(c)
    l[c].add(d)

q = deque()
ans = [0] * n
for i in range(n):
    e = [0] * n
    z = [0] * n
    e[i] = 1
    for j in f[i]:
        q.appendleft(j)
        e[j] = 1
    for j in l[i]:
        z[j] = 1
    while q:
        v = q.pop()
        for j in f[v]:
            if e[j] == 0:
                q.appendleft(j)
                e[j] = 1
                if z[j] == 0:
                    ans[i] += 1
print(' '.join(list(map(str, ans))))

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.root(self.parents[x])
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return
        else:
            if x > y:
                x, y = y, x
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            return

n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]

u = UnionFind(n)
f = [set() for _ in range(n)]
l = [set() for _ in range(n)]
for a, b in ab:
    a, b = a-1, b-1
    f[a].add(b)
    f[b].add(a)
    u.unite(a, b)
for c, d in cd:
    c, d = c-1, d-1
    l[c].add(d)
    l[d].add(c)
ans = [0] * n
for i in range(n):
    r = u.root(i)
    bl = 0
    for j in l[i]:
        if u.root(j) == r:
            bl += 1
    ans[i] = -u.parents[r] - len(f[i]) - bl - 1
print(' '.join(list(map(str, ans))))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n, m, k = map(int, input().split())
f = [set() for _ in range(n)]
l = [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    f[a].add(b)
    f[b].add(a)
for _ in range(k):
    c, d = map(int, input().split())
    c, d = c-1, d-1
    l[d].add(c)
    l[c].add(d)

q = deque()
ans = [0] * n
for i in range(n):
    e = [0] * n
    z = [0] * n
    e[i] = 1
    for j in f[i]:
        q.appendleft(j)
        e[j] = 1
    for j in l[i]:
        z[j] = 1
    while q:
        v = q.pop()
        for j in f[v]:
            if e[j] == 0:
                q.appendleft(j)
                e[j] = 1
                if z[j] == 0:
                    ans[i] += 1
print(' '.join(list(map(str, ans))))

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.root(self.parents[x])
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return
        else:
            if x > y:
                x, y = y, x
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            return

n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]

u = UnionFind(n)
f = [set() for _ in range(n)]
l = [set() for _ in range(n)]
for a, b in ab:
    a, b = a-1, b-1
    f[a].add(b)
    f[b].add(a)
    u.unite(a, b)
for c, d in cd:
    c, d = c-1, d-1
    l[c].add(d)
    l[d].add(c)
ans = [0] * n
for i in range(n):
    r = u.root(i)
    bl = 0
    for j in l[i]:
        if u.root(j) == r:
            bl += 1
    ans[i] = -u.parents[r] - len(f[i]) - bl - 1
print(' '.join(list(map(str, ans))))