Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    while d:
        temp = d.popleft()
        trace.add(temp)
        searched[temp] = 1
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
    chain = len(trace)
    for j in trace:
        ans[j] = chain - 1 - len(trace&friends[j]) - len(trace&blocks[j])
print(*ans)

Fixed submission:
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    trace.add(i)
    searched[i] = 1
    while d:
        temp = d.popleft()
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
                trace.add(x)
                searched[x] = 1
    chain = len(trace)
    for j in trace:
        ans[j] = chain - 1 - len(trace&friends[j]) - len(trace&blocks[j])
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    while d:
        temp = d.popleft()
        trace.add(temp)
        searched[temp] = 1
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
    chain = len(trace)
    for j in trace:
        ans[j] = chain - 1 - len(trace&friends[j]) - len(trace&blocks[j])
print(*ans)

Fixed submission:
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    trace.add(i)
    searched[i] = 1
    while d:
        temp = d.popleft()
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
                trace.add(x)
                searched[x] = 1
    chain = len(trace)
    for j in trace:
        ans[j] = chain - 1 - len(trace&friends[j]) - len(trace&blocks[j])
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
links = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    while d:
        temp = d.popleft()
        trace.add(temp)
        searched[temp] = 1
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
    for j in trace:
        ans[j] = len(trace) - 1 - len(trace&friends[j]) - len(trace&blocks[j])
print(*ans)

Fixed submission:
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    trace.add(i)
    searched[i] = 1
    while d:
        temp = d.popleft()
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
                trace.add(x)
                searched[x] = 1
    chain = len(trace)
    for j in trace:
        ans[j] = chain - 1 - len(trace&friends[j]) - len(trace&blocks[j])
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
links = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    while d:
        temp = d.popleft()
        trace.add(temp)
        searched[temp] = 1
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
    for person in trace:
        links[person] = trace
for i in range(N):
    ans[i] = len(links[i]) - 1 - len(links[i]&friends[i]) - len(links[i]&blocks[i])
print(*ans)

Fixed submission:
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    trace.add(i)
    searched[i] = 1
    while d:
        temp = d.popleft()
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
                trace.add(x)
                searched[x] = 1
    chain = len(trace)
    for j in trace:
        ans[j] = chain - 1 - len(trace&friends[j]) - len(trace&blocks[j])
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
links = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    while d:
        temp = d.popleft()
        trace.add(temp)
        searched[temp] = 1
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
    for person in trace:
        links[person] = trace
for i in range(N):
    ans[i] = len(links[i]) - 1 - len(links[i]&friends[i]) - len(links[i]&blocks[i])
print(*ans)

Fixed submission:
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    trace.add(i)
    searched[i] = 1
    while d:
        temp = d.popleft()
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
                trace.add(x)
                searched[x] = 1
    chain = len(trace)
    for j in trace:
        ans[j] = chain - 1 - len(trace&friends[j]) - len(trace&blocks[j])
print(*ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import scipy.sparse
from itertools import combinations
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
lil = scipy.sparse.lil_matrix((N, N), dtype = int)
for i in range(M):
    lil[AB[i][0]-1, AB[i][1]-1] = 1
    lil[AB[i][1]-1, AB[i][0]-1] = 1
lil2 = scipy.sparse.csgraph.dijkstra(lil, directed = False).astype(int)
block = np.zeros((N, N))
for i in range(K):
    block[CD[i][0]-1, CD[i][1]-1] = -100000
    block[CD[i][1]-1, CD[i][0]-1] = -100000
sug = lil2 + block
ans = [np.count_nonzero(sug[i] > 1) for i in range(N)]
print(*ans)

Fixed submission:
from collections import deque
N,M,K = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friends = [set() for _ in range(N)]
blocks = [set() for _ in range(N)]
searched = [0] * N
ans = [0] * N
d = deque()
for x, y in AB:
    friends[x-1].add(y-1)
    friends[y-1].add(x-1)
for x, y in CD:
    blocks[x-1].add(y-1)
    blocks[y-1].add(x-1)
for i in range(N):
    if searched[i]:
        continue
    trace = set()
    d.append(i)
    trace.add(i)
    searched[i] = 1
    while d:
        temp = d.popleft()
        for x in friends[temp]:
            if searched[x] == 0:
                d.append(x)
                trace.add(x)
                searched[x] = 1
    chain = len(trace)
    for j in trace:
        ans[j] = chain - 1 - len(trace&friends[j]) - len(trace&blocks[j])
print(*ans)