Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
def main():
    from collections import deque

    N, M, K = map(int, input().split())
    friends = [set() for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends[a].add(b)
        friends[b].add(a)
    blocks = [set() for _ in range(N + 1)]
    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c].add(d)
        blocks[d].add(c)

    friends_chain = []
    seen = [-1] * (N + 1)
    cnt = 0
    for person in range(1, N + 1):
        if seen[person] != -1:
            continue
        q = deque([person])
        friends_chain.append(set(q))
        while q:
            now = q.pop()
            seen[now] = cnt
            for next in friends[now]:
                if seen[next] != -1:
                    continue
                friends_chain[-1].add(next)
                q.append(next)
        cnt += 1

    ans = [0] * (N + 1)
    for person in range(1, N + 1):
        res = friends_chain[seen[person]]
        tmp_ans = len(res) - len(friends[person]) - 1
        for block in blocks[person]:
            tmp_ans -= 1 if block in res else 0
        ans[person] = (tmp_ans)
    print(*ans[1:], sep=' ')


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
def main():
    from collections import deque

    N, M, K = map(int, input().split())
    friends = [set() for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends[a].add(b)
        friends[b].add(a)
    blocks = [set() for _ in range(N + 1)]
    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c].add(d)
        blocks[d].add(c)

    friends_chain = []
    seen = [-1] * (N + 1)
    cnt = 0
    for person in range(1, N + 1):
        if seen[person] != -1:
            continue
        q = deque([person])
        friends_chain.append(set(q))
        while q:
            now = q.pop()
            seen[now] = cnt
            for next in friends[now]:
                if seen[next] != -1:
                    continue
                friends_chain[-1].add(next)
                q.append(next)
        cnt += 1

    for person in range(1, N + 1):
        res = friends_chain[seen[person]]
        tmp_ans = len(res) - len(friends[person]) - 1
        for block in blocks[person]:
            tmp_ans -= 1 if block in res else 0
        print(tmp_ans, end=' ')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
def main():
    from collections import deque

    N, M, K = map(int, input().split())
    friends = [set() for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends[a].add(b)
        friends[b].add(a)
    blocks = [set() for _ in range(N + 1)]
    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c].add(d)
        blocks[d].add(c)

    friends_chain = []
    seen = [-1] * (N + 1)
    cnt = 0
    for person in range(1, N + 1):
        if seen[person] != -1:
            continue
        q = deque([person])
        friends_chain.append(set(q))
        while q:
            now = q.pop()
            seen[now] = cnt
            for next in friends[now]:
                if seen[next] != -1:
                    continue
                friends_chain[-1].add(next)
                q.append(next)
        cnt += 1

    ans = []
    for person in range(1, N + 1):
        res = friends_chain[seen[person]]
        tmp_ans = len(res) - len(friends[person]) - 1
        for block in blocks[person]:
            tmp_ans -= 1 if block in res else 0
        ans.append(tmp_ans)
    print(*ans, sep=' ')


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
def main():
    from collections import deque

    N, M, K = map(int, input().split())
    friends = [set() for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends[a].add(b)
        friends[b].add(a)
    blocks = [set() for _ in range(N + 1)]
    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c].add(d)
        blocks[d].add(c)

    friends_chain = []
    seen = [-1] * (N + 1)
    cnt = 0
    for person in range(1, N + 1):
        if seen[person] != -1:
            continue
        q = deque([person])
        friends_chain.append(set(q))
        while q:
            now = q.pop()
            seen[now] = cnt
            for next in friends[now]:
                if seen[next] != -1:
                    continue
                friends_chain[-1].add(next)
                q.append(next)
        cnt += 1

    for person in range(1, N + 1):
        res = friends_chain[seen[person]]
        tmp_ans = len(res) - len(friends[person]) - 1
        for block in blocks[person]:
            tmp_ans -= 1 if block in res else 0
        print(tmp_ans, end=' ')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
def main():
    import sys

    sys.setrecursionlimit(10 ** 5)

    def dfs(now: int, chain: set):
        """nowを現在の頂点として，つながっている頂点をglaphに集合として記録"""
        if seen[now]:
            return chain
        seen[now] = i
        for next in friends[now]:
            chain.add(now)
            dfs(next, chain)

    N, M, K = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in [0] * M]
    CD = [tuple(map(int, input().split())) for _ in [0] * K]

    friends = [set() for _ in [0] * (N + 1)]
    for f in AB:
        friends[f[0]].add(f[1])
        friends[f[1]].add(f[0])
    blocks = [set() for _ in [0] * (N + 1)]
    for b in CD:
        blocks[b[0]].add(b[1])
        blocks[b[1]].add(b[0])

    friends_chain = []
    seen = [0] * (N + 1)
    cnt = 1
    for i in range(1, N + 1):
        if not seen[i]:
            glaph = set()
            dfs(i, glaph)
            friends_chain.append(glaph)
            cnt += 1

    ans = [0] * (N + 1)
    for person in range(1, N + 1):
        res = set(friends_chain[seen[person] - 1])
        for block in blocks[person]:
            res.discard(block)
        for friend in friends[person]:
            res.discard(friend)
        ans[person] = len(res) - 1
    
    for hoge in ans[1:]:
        print(hoge, end=' ')


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
def main():
    from collections import deque

    N, M, K = map(int, input().split())
    friends = [set() for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends[a].add(b)
        friends[b].add(a)
    blocks = [set() for _ in range(N + 1)]
    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c].add(d)
        blocks[d].add(c)

    friends_chain = []
    seen = [-1] * (N + 1)
    cnt = 0
    for person in range(1, N + 1):
        if seen[person] != -1:
            continue
        q = deque([person])
        friends_chain.append(set(q))
        while q:
            now = q.pop()
            seen[now] = cnt
            for next in friends[now]:
                if seen[next] != -1:
                    continue
                friends_chain[-1].add(next)
                q.append(next)
        cnt += 1

    for person in range(1, N + 1):
        res = friends_chain[seen[person]]
        tmp_ans = len(res) - len(friends[person]) - 1
        for block in blocks[person]:
            tmp_ans -= 1 if block in res else 0
        print(tmp_ans, end=' ')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
def main():
    import sys

    sys.setrecursionlimit(10 ** 5)
    
    def dfs(now: int, glaph: set):
        """nowを現在の頂点として，つながっている頂点をglaphに集合として記録"""
        if seen[now]:
            return glaph
        seen[now] = True
        # print(now, glaph)
        for next in friends[now]:
            glaph.add(now)
            dfs(next, glaph)

    N, M, K = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in [0] * M]
    CD = [tuple(map(int, input().split())) for _ in [0] * K]

    friends = [set() for _ in [0] * (N + 1)]
    for f in AB:
        friends[f[0]].add(f[1])
        friends[f[1]].add(f[0])
    blocks = [set() for _ in [0] * (N + 1)]
    for b in CD:
        blocks[b[0]].add(b[1])
        blocks[b[1]].add(b[0])
    # print(friends)
    # print(blocks)

    friends_chain = []
    seen = [False] * (N + 1)
    for i in range(1, N + 1):
        if not seen[i]:
            glaph = set()
            dfs(i, glaph)
            friends_chain.append(glaph)
    # print(friends_chain)

    ans = [0] * (N + 1)
    for person in range(1, N + 1):
        for chain in friends_chain:
            if person in chain:
                res = set(chain)
                # print(person, res)
                for block in blocks[person]:
                    res.discard(block)
                for friend in friends[person]:
                    res.discard(friend)
                ans[person] = len(res) - 1
                # print(res)
                # print()
    
    for hoge in ans[1:]:
        print(hoge, end=' ')


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
def main():
    from collections import deque

    N, M, K = map(int, input().split())
    friends = [set() for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends[a].add(b)
        friends[b].add(a)
    blocks = [set() for _ in range(N + 1)]
    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c].add(d)
        blocks[d].add(c)

    friends_chain = []
    seen = [-1] * (N + 1)
    cnt = 0
    for person in range(1, N + 1):
        if seen[person] != -1:
            continue
        q = deque([person])
        friends_chain.append(set(q))
        while q:
            now = q.pop()
            seen[now] = cnt
            for next in friends[now]:
                if seen[next] != -1:
                    continue
                friends_chain[-1].add(next)
                q.append(next)
        cnt += 1

    for person in range(1, N + 1):
        res = friends_chain[seen[person]]
        tmp_ans = len(res) - len(friends[person]) - 1
        for block in blocks[person]:
            tmp_ans -= 1 if block in res else 0
        print(tmp_ans, end=' ')


if __name__ == '__main__':
    main()