Problem p02678 (python)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
ways = [tuple(map(int, input().split())) for _ in range(m)]
ans = [None] * (n+1)

hush = {}
hush[1] = True
for i in range(2, n+1):
    hush[i] = False
table = [list() for _ in range(n+1)]
for a, b in ways:
    table[a].append(b)
    table[b].append(a)

que = deque([1])
while len(que) > 0:
    room = que.popleft()
    for next in table[room]:
        if hush[next] == False:
            ans[next] = room
            que.append(next)
            hush[next] = True

print('Yes')
for i in range(2, n+1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ways = [tuple(map(int, input().split())) for _ in range(m)]

table = [list() for _ in range(n+1)]
hush = {}
hush2 = {}
for i in range(1, n+1):
    hush[i] = False
    hush2[i] = False
ans = [0 for _ in range(n+1)]

for a, b in ways:
    table[a].append(b)
    table[b].append(a)

hush[1] = True

def bfs(i):
    if hush2[i] == True: return
    else: hush2[i] = True
    for room in table[i]:
        if hush[room] == False:
            ans[room] = i
            hush[room] = True
    for room in table[i]:
        bfs(room)

bfs(1)

print('Yes')
for i in range(2, n+1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
road = [tuple(map(int, input().split())) for _ in range(m)]

table = [list() for _ in range(n+1)]
ans = [0 for _ in range(n+1)]
hush = {}

for i in range(1, n+1):
    hush[i] = False

for a, b in road:
    table[a].append(b)
    table[b].append(a)

def bfs(i):
    hush[i] = True
    rec = []
    for j in table[i]:
        if hush[j] == False:
            ans[j] = i
            hush[j] = True
            rec.append(j)
    for j in rec:
        bfs(j)

bfs(1)

print('Yes')
for i in range(2, n+1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**10)
n, m = map(int, input().split())
road = [tuple(map(int, input().split())) for _ in range(m)]

table = [list() for _ in range(n+1)]
ans = [0 for _ in range(n+1)]
hush = {}

for i in range(1, n+1):
    hush[i] = False

for a, b in road:
    table[a].append(b)
    table[b].append(a)

def bfs(i):
    hush[i] = True
    rec = []
    for j in table[i]:
        if hush[j] == False:
            ans[j] = i
            hush[j] = True
            rec.append(j)
    for j in rec:
        bfs(j)

bfs(1)

print('Yes')
for i in range(2, n+1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
sys.setrecursionlimit(10**5)
n, m = map(int, input().split())
road = [tuple(map(int, input().split())) for _ in range(m)]

table = [list() for _ in range(n+1)]
ans = [0 for _ in range(n+1)]
hush = {}

for i in range(1, n+1):
    hush[i] = False

for a, b in road:
    table[a].append(b)
    table[b].append(a)

def bfs(i):
    hush[i] = True
    rec = []
    for j in table[i]:
        if hush[j] == False:
            ans[j] = i
            hush[j] = True
            rec.append(j)
    for j in rec:
        bfs(j)

bfs(1)

print('Yes')
for i in range(2, n+1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
road = [tuple(map(int, input().split())) for _ in range(m)]

table = [list() for _ in range(n+1)]
ans = [0 for _ in range(n+1)]
hush = {}

for i in range(1, n+1):
    hush[i] = False

for a, b in road:
    table[a].append(b)
    table[b].append(a)

def bfs(i):
    hush[i] = True
    rec = []
    for j in table[i]:
        if hush[j] == False:
            ans[j] = i
            hush[j] = True
            rec.append(j)
    for j in rec:
        bfs(j)

bfs(1)

print('Yes')
for i in range(2, n+1):
    print(ans[i])