Buggy python submission (verdict: Runtime Error):
def dfs(graph, start):
    visited = set([start])
    stack = [start]

    while stack:
        v = stack[-1]
        for w in graph[v]:
            if w not in visited:
                break

        if w in visited:
            stack.pop()
            yield v
        else:
            stack.append(w)
            visited.add(w)


def read_graph(nodes, edges):
    graph = [[] for _ in range(nodes)]
    for _ in range(edges):
        a, b = (int(x) - 1 for x in input().split())
        graph[a].append(b)
        graph[b].append(a)

    return graph


def count_candidates(n, counts, groups, block, friend):
    for i in range(n):
        count = counts[groups[i]]
        for v in block[i]:
            if groups[i] == groups[v]:
                count -= 1

        count -= len(friend[i])
        count -= 1
        yield count


def main():
    n, m, k = map(int, input().split())
    friend = read_graph(n, m)
    block = read_graph(n, k)

    groups = [-1 for _ in range(n)]
    counts = []
    i = 0
    group_id = 0
    while i < n:
        if groups[i] != -1:
            i += 1
            continue

        for j, v in enumerate(dfs(friend, i)):
            groups[v] = group_id

        counts.append(j + 1)
        group_id += 1

    print(" ".join(str(i) for i in count_candidates(n, counts, groups, block, friend)))


if __name__ == "__main__":
    main()


Fixed submission:
def dfs(graph, start):
    visited = set()
    stack = [start]

    while stack:
        v = stack.pop()
        if v not in visited:
            stack.extend(graph[v])
            visited.add(v)
            yield v


def read_graph(nodes, edges):
    graph = [[] for _ in range(nodes)]
    for _ in range(edges):
        a, b = (int(x) - 1 for x in input().split())
        graph[a].append(b)
        graph[b].append(a)

    return graph


def count_candidates(n, counts, groups, block, friend):
    for i in range(n):
        count = counts[groups[i]]
        for v in block[i]:
            if groups[i] == groups[v]:
                count -= 1

        count -= len(friend[i])
        count -= 1
        yield count


def main():
    n, m, k = map(int, input().split())
    friend = read_graph(n, m)
    block = read_graph(n, k)

    groups = [-1 for _ in range(n)]
    counts = []
    i = 0
    group_id = 0
    while i < n:
        if groups[i] != -1:
            i += 1
            continue

        for j, v in enumerate(dfs(friend, i)):
            groups[v] = group_id

        counts.append(j + 1)
        group_id += 1

    print(" ".join(str(i) for i in count_candidates(n, counts, groups, block, friend)))


if __name__ == "__main__":
    main()

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


def dfs(graph, start):
    visited = set()
    stack = [start]
 
    while stack:
        v = stack.pop()
        if v not in visited:
            stack.extend(graph[v])
            visited.add(v)
            yield v

def read_graph(nodes, edges):
    graph = [set() for _ in range(nodes)]
    for _ in range(edges):
        a, b = (int(x) - 1 for x in input().split())
        graph[a].add(b)
        graph[b].add(a)
 
    return graph

N, M, K = map(int, input().split())

friends = read_graph(N, M)
blockings = read_graph(N, K)

candidates = [None for _ in range(N)]
for i in range(N):
    if candidates[i] is not None:
        continue

    s = set()
    for j in dfs(friends, i):
        s.add(j)
        candidates[j] = s
    

print(
    " ".join(
        str(len(candidates[i] - friends[i] - blockings[i]) - 1) for i in range(N)
    )
)


Fixed submission:
def dfs(graph, start):
    visited = set()
    stack = [start]

    while stack:
        v = stack.pop()
        if v not in visited:
            stack.extend(graph[v])
            visited.add(v)
            yield v


def read_graph(nodes, edges):
    graph = [[] for _ in range(nodes)]
    for _ in range(edges):
        a, b = (int(x) - 1 for x in input().split())
        graph[a].append(b)
        graph[b].append(a)

    return graph


def count_candidates(n, counts, groups, block, friend):
    for i in range(n):
        count = counts[groups[i]]
        for v in block[i]:
            if groups[i] == groups[v]:
                count -= 1

        count -= len(friend[i])
        count -= 1
        yield count


def main():
    n, m, k = map(int, input().split())
    friend = read_graph(n, m)
    block = read_graph(n, k)

    groups = [-1 for _ in range(n)]
    counts = []
    i = 0
    group_id = 0
    while i < n:
        if groups[i] != -1:
            i += 1
            continue

        for j, v in enumerate(dfs(friend, i)):
            groups[v] = group_id

        counts.append(j + 1)
        group_id += 1

    print(" ".join(str(i) for i in count_candidates(n, counts, groups, block, friend)))


if __name__ == "__main__":
    main()

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


def friend_candidates(i, friends, visited=None):
    visited = set([i])
    stack = list(friends[i])

    while stack:
        v = stack.pop()
        if v in visited:
            continue

        stack.extend(friends[v])
        visited.add(v)

    return visited


N, M, K = map(int, input().split())

friends = collections.defaultdict(set)
for _ in range(M):
    A, B = map(int, input().split())
    friends[A].add(B)
    friends[B].add(A)

blockings = collections.defaultdict(set)
for _ in range(K):
    C, D = map(int, input().split())
    blockings[C].add(D)
    blockings[D].add(C)


table = {}
for i in range(1, N + 1):
    if i in table:
        continue

    candidates = friend_candidates(i, friends)
    for j in candidates:
        table[j] = candidates

print(
    " ".join(
        str(len(table[i] - friends[i] - blockings[i]) - 1) for i in range(1, N + 1)
    )
)


Fixed submission:
def dfs(graph, start):
    visited = set()
    stack = [start]

    while stack:
        v = stack.pop()
        if v not in visited:
            stack.extend(graph[v])
            visited.add(v)
            yield v


def read_graph(nodes, edges):
    graph = [[] for _ in range(nodes)]
    for _ in range(edges):
        a, b = (int(x) - 1 for x in input().split())
        graph[a].append(b)
        graph[b].append(a)

    return graph


def count_candidates(n, counts, groups, block, friend):
    for i in range(n):
        count = counts[groups[i]]
        for v in block[i]:
            if groups[i] == groups[v]:
                count -= 1

        count -= len(friend[i])
        count -= 1
        yield count


def main():
    n, m, k = map(int, input().split())
    friend = read_graph(n, m)
    block = read_graph(n, k)

    groups = [-1 for _ in range(n)]
    counts = []
    i = 0
    group_id = 0
    while i < n:
        if groups[i] != -1:
            i += 1
            continue

        for j, v in enumerate(dfs(friend, i)):
            groups[v] = group_id

        counts.append(j + 1)
        group_id += 1

    print(" ".join(str(i) for i in count_candidates(n, counts, groups, block, friend)))


if __name__ == "__main__":
    main()

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


def friend_candidates(i, friends, visited=None):
    visited = set([i])
    stack = list(friends[i])

    while stack:
        v = stack.pop()
        if v in visited:
            continue

        stack.extend(friends[v])
        visited.add(v)

    return visited


N, M, K = map(int, input().split())

friends = collections.defaultdict(set)
for _ in range(M):
    A, B = map(int, input().split())
    friends[A].add(B)
    friends[B].add(A)

blockings = collections.defaultdict(set)
for _ in range(K):
    C, D = map(int, input().split())
    blockings[C].add(D)
    blockings[D].add(C)


table = {}
for i in range(1, N + 1):
    if i in table:
        continue

    candidates = friend_candidates(i, friends)
    for j in candidates:
        table[j] = candidates

print(
    " ".join(
        str(len(table[i] - friends[i] - blockings[i]) - 1) for i in range(1, N + 1)
    )
)


Fixed submission:
def dfs(graph, start):
    visited = set()
    stack = [start]

    while stack:
        v = stack.pop()
        if v not in visited:
            stack.extend(graph[v])
            visited.add(v)
            yield v


def read_graph(nodes, edges):
    graph = [[] for _ in range(nodes)]
    for _ in range(edges):
        a, b = (int(x) - 1 for x in input().split())
        graph[a].append(b)
        graph[b].append(a)

    return graph


def count_candidates(n, counts, groups, block, friend):
    for i in range(n):
        count = counts[groups[i]]
        for v in block[i]:
            if groups[i] == groups[v]:
                count -= 1

        count -= len(friend[i])
        count -= 1
        yield count


def main():
    n, m, k = map(int, input().split())
    friend = read_graph(n, m)
    block = read_graph(n, k)

    groups = [-1 for _ in range(n)]
    counts = []
    i = 0
    group_id = 0
    while i < n:
        if groups[i] != -1:
            i += 1
            continue

        for j, v in enumerate(dfs(friend, i)):
            groups[v] = group_id

        counts.append(j + 1)
        group_id += 1

    print(" ".join(str(i) for i in count_candidates(n, counts, groups, block, friend)))


if __name__ == "__main__":
    main()

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


def friend_candidates(i, friends, visited=None):
    visited = set([i])
    stack = list(friends[i])

    while stack:
        v = stack.pop()
        if v in visited:
            continue

        stack.extend(friends[v])
        visited.add(v)

    return visited


N, M, K = map(int, input().split())

friends = collections.defaultdict(list)
for _ in range(M):
    A, B = map(int, input().split())
    friends[A].append(B)
    friends[B].append(A)

blockings = collections.defaultdict(list)
for _ in range(K):
    C, D = map(int, input().split())
    blockings[C].append(D)
    blockings[D].append(C)


table = {}
for i in range(1, N + 1):
    if i in table:
        continue

    candidates = list(friend_candidates(i, friends))
    for j in candidates:
        table[j] = candidates

print(
    " ".join(
        str(
            len(table[i])
            - len(friends[i])
            - len(set(blockings[i]).intersection(table[i]))
            - 1
        )
        for i in range(1, N + 1)
    )
)


Fixed submission:
def dfs(graph, start):
    visited = set()
    stack = [start]

    while stack:
        v = stack.pop()
        if v not in visited:
            stack.extend(graph[v])
            visited.add(v)
            yield v


def read_graph(nodes, edges):
    graph = [[] for _ in range(nodes)]
    for _ in range(edges):
        a, b = (int(x) - 1 for x in input().split())
        graph[a].append(b)
        graph[b].append(a)

    return graph


def count_candidates(n, counts, groups, block, friend):
    for i in range(n):
        count = counts[groups[i]]
        for v in block[i]:
            if groups[i] == groups[v]:
                count -= 1

        count -= len(friend[i])
        count -= 1
        yield count


def main():
    n, m, k = map(int, input().split())
    friend = read_graph(n, m)
    block = read_graph(n, k)

    groups = [-1 for _ in range(n)]
    counts = []
    i = 0
    group_id = 0
    while i < n:
        if groups[i] != -1:
            i += 1
            continue

        for j, v in enumerate(dfs(friend, i)):
            groups[v] = group_id

        counts.append(j + 1)
        group_id += 1

    print(" ".join(str(i) for i in count_candidates(n, counts, groups, block, friend)))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import collections


def friend_candidates(i, friends, visited=None):
    if visited is None:
        visited = set()

    for j in friends[i]:
        if j not in visited:
            yield j
            visited.add(j)
            yield from friend_candidates(j, friends, visited=visited)


N, M, K = map(int, input().split())

friends = collections.defaultdict(list)
for _ in range(M):
    A, B = map(int, input().split())
    friends[A].append(B)
    friends[B].append(A)

blockings = collections.defaultdict(list)
for _ in range(K):
    C, D = map(int, input().split())
    blockings[C].append(D)
    blockings[D].append(C)


table = {}
for i in range(1, N + 1):
    if i in table:
        continue

    candidates = list(friend_candidates(i, friends))
    for j in candidates:
        table[j] = candidates


print(
    " ".join(
        str(
            len(table[i])
            - len(friends[i])
            - len(set(blockings[i]).intersection(table[i]))
            - 1
        )
        for i in range(1, N + 1)
    )
)


Fixed submission:
def dfs(graph, start):
    visited = set()
    stack = [start]

    while stack:
        v = stack.pop()
        if v not in visited:
            stack.extend(graph[v])
            visited.add(v)
            yield v


def read_graph(nodes, edges):
    graph = [[] for _ in range(nodes)]
    for _ in range(edges):
        a, b = (int(x) - 1 for x in input().split())
        graph[a].append(b)
        graph[b].append(a)

    return graph


def count_candidates(n, counts, groups, block, friend):
    for i in range(n):
        count = counts[groups[i]]
        for v in block[i]:
            if groups[i] == groups[v]:
                count -= 1

        count -= len(friend[i])
        count -= 1
        yield count


def main():
    n, m, k = map(int, input().split())
    friend = read_graph(n, m)
    block = read_graph(n, k)

    groups = [-1 for _ in range(n)]
    counts = []
    i = 0
    group_id = 0
    while i < n:
        if groups[i] != -1:
            i += 1
            continue

        for j, v in enumerate(dfs(friend, i)):
            groups[v] = group_id

        counts.append(j + 1)
        group_id += 1

    print(" ".join(str(i) for i in count_candidates(n, counts, groups, block, friend)))


if __name__ == "__main__":
    main()