Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m,k = map(int,input().split()) 
g = [set() for _ in range(n)]
bl = [set() for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    g[a].add(b)
    g[b].add(a)

for _ in range(k):
    c,d = map(int,input().split())
    c,d = c-1,d-1
    bl[c].add(d)
    bl[d].add(c)

ans = [0]*n 

def bfs():
    for u in range(n):
        q = deque([u])
        d = [False]*n
        d[u] = True
        l = {u}
        while q:
            v = q.popleft()
            for i in g[v]:
                if d[i] == False:
                    l.add(i)
                    d[i] = True
                    q.append(i)
        for p in l:
            ans[p] = len(l) - len(l&g[p]) - len(l&bl[p]) - 1
    
bfs()

print(*ans)

Fixed submission:
n,m,k = map(int,input().split())
par = [-1]*(n+1)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
def size(x):
    return -par[find(x)]
g = [[] for _ in range(n+1)]
b = [[] for _ in range(n+1)]
for _ in range(m):
    s,t = map(int,input().split())
    unite(s,t)
    g[s].append(t)
    g[t].append(s)
for _ in range(k):
    s,t = map(int,input().split())
    b[s].append(t)
    b[t].append(s)
for i in range(1,n+1):
    ans = size(i)-1-len(g[i])
    for e in b[i]:
        if same(i,e):
            ans -= 1
    print(ans,end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m,k = map(int,input().split()) 
g = [[] for _ in range(n)]
bl = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    g[a].append(b)
    g[b].append(a)

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


def bfs(u):
    q = deque([u])
    d = [None]*n
    d[u] = 0
    while q:
        v = q.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                q.append(i)
    return d


for i in range(n):
    d = bfs(i)
    ans = len([e for e in d if e != None])-len([e for e in range(len(d)) if d[e] != None and (e in g[i] or e in bl[i])])-1
    print(ans,end = " ")

Fixed submission:
n,m,k = map(int,input().split())
par = [-1]*(n+1)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
def size(x):
    return -par[find(x)]
g = [[] for _ in range(n+1)]
b = [[] for _ in range(n+1)]
for _ in range(m):
    s,t = map(int,input().split())
    unite(s,t)
    g[s].append(t)
    g[t].append(s)
for _ in range(k):
    s,t = map(int,input().split())
    b[s].append(t)
    b[t].append(s)
for i in range(1,n+1):
    ans = size(i)-1-len(g[i])
    for e in b[i]:
        if same(i,e):
            ans -= 1
    print(ans,end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m,k = map(int,input().split()) 
g = [[] for _ in range(n)]
bl = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    g[a].append(b)
    g[b].append(a)

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


def bfs(u):
    q = deque([u])
    d = [None]*n
    d[u] = 0
    while q:
        v = q.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                q.append(i)
    return d


for i in range(n):
    ans = 0
    d = bfs(i)
    for j in range(len(d)):
        if j != i and d[j] != None and j not in g[i]:
            if j not in bl[i]:
                ans += 1
    print(ans,end = " ")


Fixed submission:
n,m,k = map(int,input().split())
par = [-1]*(n+1)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
def size(x):
    return -par[find(x)]
g = [[] for _ in range(n+1)]
b = [[] for _ in range(n+1)]
for _ in range(m):
    s,t = map(int,input().split())
    unite(s,t)
    g[s].append(t)
    g[t].append(s)
for _ in range(k):
    s,t = map(int,input().split())
    b[s].append(t)
    b[t].append(s)
for i in range(1,n+1):
    ans = size(i)-1-len(g[i])
    for e in b[i]:
        if same(i,e):
            ans -= 1
    print(ans,end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m,k = map(int,input().split()) 
g = [[] for _ in range(n)]
bl = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    g[a].append(b)
    g[b].append(a)

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


def bfs(u):
    q = deque([u])
    d = [None]*n
    d[u] = 0
    while q:
        v = q.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                q.append(i)
    return d


for i in range(n):
    ans = 0
    d = bfs(i)
    for j in range(len(d)):
        if j != i and d[j] != None and j not in g[i]:
            if j not in bl[i]:
                ans += 1
    print(ans,end = " ")

Fixed submission:
n,m,k = map(int,input().split())
par = [-1]*(n+1)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
def size(x):
    return -par[find(x)]
g = [[] for _ in range(n+1)]
b = [[] for _ in range(n+1)]
for _ in range(m):
    s,t = map(int,input().split())
    unite(s,t)
    g[s].append(t)
    g[t].append(s)
for _ in range(k):
    s,t = map(int,input().split())
    b[s].append(t)
    b[t].append(s)
for i in range(1,n+1):
    ans = size(i)-1-len(g[i])
    for e in b[i]:
        if same(i,e):
            ans -= 1
    print(ans,end=" ")