Problem p03575 (python)

Fixed submission:
from collections import deque
N, M = map(int, input().split())

graph = [set() for _ in range(N + 1)]
edge = []
for m in range(M):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)
    edge.append([a, b])

ans = 0
for m in range(M):
    Bridge = True
    fr, to = edge[m][0], edge[m][1]
    V = {fr} | set(graph[fr]) - {to}
    que = set(graph[fr]) - {to}
    while que:
        node = que.pop()
        for new_node in graph[node]:
            if new_node == to:
                Bridge = False
                break
            if new_node not in V:
                que.add(new_node)
                V.add(new_node)
        else:
            continue
        break
    if Bridge:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
N, M = map(int, input().split())

graph = [set() for _ in range(N + 1)]
edge = [[] for _ in range(N + 1)]
for m in range(M):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)
    edge[m + 1] = [a, b]

ans = 0
for m in range(M):
    Bridge = True
    fr, to = edge[m + 1][0], edge[m + 1][1]
    V = {fr} | set(graph[fr]) - {to}
    que = set(graph[fr]) - {to}
    while que:
        node = que.pop()
        for new_node in graph[node]:
            if new_node == to:
                Bridge = False
                break
            if new_node not in V:
                que.add(new_node)
                V.add(new_node)
        else:
            continue
        break
    if Bridge:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
N, M = map(int, input().split())

graph = [[] for _ in range(N + 1)]
edge = [[] for _ in range(N + 1)]
for m in range(M):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
    edge[m + 1] = [a, b]

ans = 0
for m in range(M):
    Bridge = True
    fr, to = edge[m + 1][0], edge[m + 1][1]
    V = {fr} | set(graph[fr]) - {to}
    que = deque(set(graph[fr]) - {to})
    while que:
        node = que.pop()
        for new_node in graph[node]:
            if new_node == to:
                Bridge = False
                break
            if new_node not in V:
                que.append(new_node)
                V.add(new_node)
        else:
            continue
        break
    if Bridge:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
N, M = map(int, input().split())

graph = [[] for _ in range(N + 1)]
edge = [[] for _ in range(N + 1)]
for m in range(M):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
    edge[m + 1] = [a, b]

ans = 0
for m in range(M):
    Bridge = True
    fr, to = edge[m + 1][0], edge[m + 1][1]
    V = {fr} | set(graph[fr]) - {to}
    que = deque(set(graph[fr]) - {to})
    while que:
        node = que.pop()
        for new_node in graph[node]:
            if new_node == to:
                Bridge = False
                break
            if new_node not in V:
                que.append(new_node)
                V.add(new_node)
        else:
            continue
    if Bridge:
        ans += 1
print(ans)