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

n,m,k = map(int,input().split())

f_lst = [[] for _ in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    f_lst[a].append(b)
    f_lst[b].append(a)

b_lst = [[] for _ in range(n+1)]
for i in range(k):
    c,d = map(int,input().split())
    b_lst[c].append(d)
    b_lst[d].append(c)

res = []
for i in range(1, n+1):
    tmp = []
    visited = [False]*(n+1)
    visited[i] = True
    que = deque(f_lst[i])
    while que:
        v = que.popleft()
        if visited[v]:
            continue
        else:
            visited[v] = True
            tmp.append(v)
            for w in f_lst[v]:
                que.append(w)
    res.append(tmp)

ans = []
for i in range(n):
    x,y,z = set(res[i]), set(f_lst[i+1]), set(b_lst[i+1])
    ans.append(len(x-y-z))
print(*ans)

Fixed submission:
n,m,k = map(int,input().split())
par = [-1]*n
num = [0]*n
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x==y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

def same(x,y):
    return find(x) == find(y)

def size(x):
    return -par[find(x)]

for i in range(m):
    a,b = map(int,input().split())
    unite(a-1, b-1)
    num[a-1] += 1
    num[b-1] += 1

edge = [[] for i in range(n)]

for i in range(k):
    c,d = map(int,input().split())
    edge[c-1].append(d-1)
    edge[d-1].append(c-1)

for i in range(n):
    cnt = size(i) - num[i] - 1
    for e in edge[i]:
        if same(e, i):
            cnt -= 1
    print(cnt, end=' ')

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

n,m,k = map(int,input().split())

f_lst = [[] for _ in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    f_lst[a].append(b)
    f_lst[b].append(a)

b_lst = [[] for _ in range(n+1)]
for i in range(k):
    c,d = map(int,input().split())
    b_lst[c].append(d)
    b_lst[d].append(c)

res = []
for i in range(1, n+1):
    tmp = []
    visited = [False]*(n+1)
    visited[i] = True
    que = deque(f_lst[i])
    while que:
        v = que.popleft()
        if visited[v]:
            continue
        else:
            visited[v] = True
            tmp.append(v)
            for w in f_lst[v]:
                que.append(w)
    res.append(tmp)

ans = []
for i in range(n):
    x,y,z = set(res[i]), set(f_lst[i+1]), set(b_lst[i+1])
    ans.append(len(x-y-z))
print(*ans)

Fixed submission:
n,m,k = map(int,input().split())
par = [-1]*n
num = [0]*n
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x==y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

def same(x,y):
    return find(x) == find(y)

def size(x):
    return -par[find(x)]

for i in range(m):
    a,b = map(int,input().split())
    unite(a-1, b-1)
    num[a-1] += 1
    num[b-1] += 1

edge = [[] for i in range(n)]

for i in range(k):
    c,d = map(int,input().split())
    edge[c-1].append(d-1)
    edge[d-1].append(c-1)

for i in range(n):
    cnt = size(i) - num[i] - 1
    for e in edge[i]:
        if same(e, i):
            cnt -= 1
    print(cnt, end=' ')