Problem p02678 (python)

Fixed submission:
from collections import deque

n,m = list(map(int,input().split()))
e = [[] for _ in range(n+1)]

for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)
q = deque()
q.append(1)
t = [-1 for _ in range(n+1)]

while len(q):
    node = q.popleft()

    for i in range(len(e[node])):
        nex = e[node][i]
        if t[nex] == -1:
            q.append(nex)
            t[nex] = node
print("Yes")
for i in range(2,n+1):
    print(t[i])

Buggy submission (verdict: Runtime Error):
from collections import deque

n,m = list(map(int,input().split()))
e = [[] for _ in range(m+1)]

for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)
q = deque()
q.append(1)
t = [-1 for _ in range(n+1)]

while len(q):
    node = q.popleft()

    for i in range(len(e[node])):
        nex = e[node][i]
        if t[nex] == -1:
            q.append(nex)
            t[nex] = node
print("Yes")
for i in range(2,n+1):
    print(t[i])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,m = list(map(int,input().split()))
e = [[] for _ in range(m+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)
q = deque()
q.append(1)
s = [float('inf') for _ in range(n+1)]
t = [-1 for _ in range(n+1)]
s[1] = 0
# print(e)
while len(q):
    node = q.popleft()

    for i in range(len(e[node])):
        nex = e[node][i]
        if t[nex] == -1:
            # print(nex,node)
            q.append(nex)
            t[nex] = node
# print(s,t,e)
print("Yes")
for i in range(2,n+1):
    print(t[i])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,m = list(map(int,input().split()))
e = [[] for _ in range(m+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)
q = deque()
q.append(1)
s = [float('inf') for _ in range(n+1)]
t = [-1 for _ in range(n+1)]
s[1] = 0
while len(q):
    node = q.pop()
    step = s[node]+1
    for i in range(len(e[node])):
        nex = e[node][i]
        if s[nex] > step:
            q.append(nex)
            s[nex] = step
            t[nex] = node
# print(s,t,e)
print("Yes")
for i in range(2,n+1):
    print(t[i])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,m = list(map(int,input().split()))
e = [[] for _ in range(m+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)

q = deque()
q.append(1)

s = [float('inf') for _ in range(n+1)]
t = [-1 for _ in range(n+1)]
s[1] = 0
while len(q):
    node = q.pop()
    step = s[node]+1
    for i in range(len(e[node])):
        nex = e[node][i]
        if s[nex] > step:
            q.append(nex)
            s[nex] = step
            t[nex] = node
# print(s,t,e)
print("Yes")
for i in range(2,n+1):
    print(t[i])

Buggy submission (verdict: Runtime Error):
from collections import deque 
n,m = list(map(int,input().split()))
e = [[] for _ in range(m+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)

q = deque()
q.append(1)

s = [-1 for _ in range(n+1)]
s[1] = 0
while len(q):
    node = q.pop()
    for i in range(len(e[node])):
        nex = e[node][i]
        if s[nex] == -1:
            q.append(nex)
            s[nex] = node
# print(s,t,e)
print("Yes")
for i in range(2,n+1):
    print(s[i])

Buggy submission (verdict: Runtime Error):
from collections import deque 
n,m = list(map(int,input().split()))
e = [[] for _ in range(m+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)

q = deque()
q.append(1)

s = [[(10**5+1) for _ in range(2)] for _ in range(n+1)]
s[1][0] = 0
while len(q):
    node = q.pop()
    step = s[node][0]
    for i in range(len(e[node])):
        nex = e[node][i]

        if s[nex][0] > step +1:
            q.append(nex)
            s[nex][0] = step + 1
            s[nex][1] = node
# print(s,t,e)
print("Yes")
for i in range(2,n+1):
    print(s[i][1])

Buggy submission (verdict: Runtime Error):
from collections import deque 
n,m = list(map(int,input().split()))
e = [[] for _ in range(m+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)

q = deque()
q.append(1)

s = [float('inf') for _ in range(n+1)]
t = [float('inf') for _ in range(n+1)]
s[1] = 0
t[1] = 0
while len(q):
    node = q.pop()
    step = s[node]
    for i in range(len(e[node])):
        if s[e[node][i]] > step +1:
            q.append(e[node][i])
            s[e[node][i]] = step + 1
            t[e[node][i]] = node
# print(s,t,e)
for i in range(2,n+1):
    print(t[i])