Problem p02678 (python)

Fixed submission:
from collections import deque
n, m = map(int, input().split())
route = [[] for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b - 1)
    route[b-1].append(a - 1)

next_queue = deque()
sign = [-1 for i in range(n)]
sign[0] = 999

next_queue.append(0)

while next_queue:
    current_number = next_queue.popleft()
    for room in route[current_number]:
        if sign[room] == -1:
            sign[room] = current_number
            next_queue.append(room)
print("Yes")
for i in range(1, n):
    print(sign[i] + 1)

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
route = [[] for i in range(m)]

for i in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b - 1)
    route[b-1].append(a - 1)

next_queue = deque()
sign = [-1] * n
sign[0] = 999

next_queue.append(0)

while next_queue:
    current_number = next_queue.popleft()
    for room in route[current_number]:
        if sign[room] == -1:
            sign[room] = current_number
            next_queue.append(room)
print("Yes")
for i in range(1, n):
    print(sign[i] + 1)

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
route = [[] for i in range(m)]

for i in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b)
    route[b-1].append(a)

next_queue = deque()
sign = [-1] * n
sign[0] = 999

next_queue.append(1)

while next_queue:
    current_number = next_queue.popleft()
    for room in route[current_number - 1]:
        if sign[room - 1] == -1:
            sign[room - 1] = current_number
            next_queue.append(room)
print("Yes")
for i in range(1, n):
    print(sign[i])

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
route = [[] for i in range(m)]

for i in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b)
    route[b-1].append(a)

next_queue = deque()
sign = [-1] * n

next_queue.append(1)

while next_queue:
    current_number = next_queue.popleft()
    for room in route[current_number - 1]:
        if sign[room - 1] == -1:
            sign[room - 1] = current_number
            next_queue.append(room)
print("Yes")
for i in range(1, n):
    print(sign[i])

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
A = [0] * m
B = [0] * m
for i in range(m):
    A[i], B[i] = map(int, input().split())

next_queue = deque()
sign = [-1] * n

next_queue.append(1)

while next_queue:
    current_number = next_queue.popleft()
    for i, _ in reversed(list(enumerate(A))):
        if A[i] == current_number:
            if sign[B[i] - 1] == -1:
                sign[B[i] - 1] = current_number
                if B[i] != 1:
                    next_queue.append(B[i])
                A.pop(i)
                B.pop(i)
        if B[i] == current_number:
            if sign[A[i] - 1] == -1:
                sign[A[i] - 1] = current_number
                if A[i] != 1:
                    next_queue.append(A[i])
                A.pop(i)
                B.pop(i)
print("Yes")
for i in range(1, n):
    print(sign[i])

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
A = [0] * m
B = [0] * m
for i in range(m):
    A[i], B[i] = map(int, input().split())

next_queue = deque()
sign = [-1] * n

next_queue.append(1)

while next_queue:
    current_number = next_queue.popleft()
    for i, _ in enumerate(A):
        if A[i] == current_number:
            if sign[B[i] - 1] == -1:
                sign[B[i] - 1] = current_number
                if B[i] != 1:
                    next_queue.append(B[i])
                A.pop(i)
                B.pop(i)
        if B[i] == current_number:
            if sign[A[i] - 1] == -1:
                sign[A[i] - 1] = current_number
                if A[i] != 1:
                    next_queue.append(A[i])
                A.pop(i)
                B.pop(i)
print("Yes")
for i in range(1, n):
    print(sign[i])