Problem p02678 (python)

Fixed submission:
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)

que = queue.Queue()
que.put(1)
result = [-1]*(N+1)
result[1] = 0
while(True):
    if que.empty():
        break
    start = que.get()
    for i in tree[start]:
        if result[i] == -1:
            result[i] = start
            que.put(i)

if -1 in result[2:]:
    print("No")
else:
    print("Yes")
    for i in result[2:]:
        print(i)

Buggy submission (verdict: Runtime Error):
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)

que = queue.Queue()
que.put(1)

result = [-1]*(N+1)
result[1] = 0
while(True):
    if que.empty():
        break
    start = que.get()
    print("start"+str(start))
    print(que)
    for i in tree[start]:
        if result[i] == -1:
            result[i] = start
            que.put(i)

if -1 in result[2:]:
    print("No")
else:
    print("Yes")
    for i in range(2,N+1):
        print(result[i])

Buggy submission (verdict: Runtime Error):
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)

que = queue.Queue()
que.put(1)

result = [-1]*(N+1)
while(True):
    if que.empty():
        break
    start = que.get()
    for i in tree[start]:
        if result[i] == -1:
            result[i] = start
            que.put(i)

if -1 in result[2:]:
    print("No")
else:
    print("Yes")
    for i in range(2,N+1):
        print(result[i])

Buggy submission (verdict: Runtime Error):
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)

que = queue.Queue()
que.put(1)

result = [-1]*(N+1)
while(True):
    if que.empty():
        break
    start = que.get()
    for i in tree[start]:
        if result[i] == -1:
            result[i] = start
            que.put(i)


print("Yes")
for i in range(2,N+1):
    print(result[i])

Buggy submission (verdict: Runtime Error):
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)

que = queue.Queue()
que.put(1)
rank = [-1]*(N+1)
result = [0]*(N+1)
while(True):
    if que.empty():
        break
    start = que.get()
    for i in tree[start]:
        if rank[i] == -1:
            rank[i] = rank[start]+1
            result[i] = start
            que.put(i)


print("Yes")
for i in range(2,N+1):
    print(result[i])

Buggy submission (verdict: Runtime Error):
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append([b,a])
    tree[b].append([a,b])

que = queue.Queue()
que.put(1)
result = [[-1,100000] for _ in range(N+1)]
result[1][1] = 0

while(True):
    if que.empty():
        break
    nex = que.get()
    
    for i in tree[nex]:
        if result[i[0]][0] == -1  :
            result[i[0]][0] = nex
            result[i[0]][1] = result[nex][1] +1

            
            que.put(i[0])

for i in range(2,N+1):
    for j in tree[i]:
        if result[j[0]][1] == result[i][1] -1:
            result[i][0] = j[0] 
result = result[2:]
if result.count(-1) !=0:
    print("No")
else :
    print("Yes")
    for i in result:
        print(i[0])

Buggy submission (verdict: Runtime Error):
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append([b,a])
    tree[b].append([a,b])

que = queue.Queue()
que.put(1)
result = [[-1,100000] for _ in range(N+1)]
result[1][1] = 0

while(True):
    if que.empty():
        break
    nex = que.get()
    
    for i in tree[nex]:
        if result[i[0]][0] == -1  :
            result[i[0]][0] = nex
            result[i[0]][1] = result[nex][1] +1

            
            que.put(i[0])

for i in range(2,N+1):
    for j in tree[i]:
        if result[j[0]][1] == result[i][1] -1:
            result[i][0] = j[0] 
result = result[2:]
if result.count(-1) !=0:
    print("No")
else :
    print("Yes")
    for i in result:
        print([i[0]])

Buggy submission (verdict: Runtime Error):
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append([b,a])
    tree[b].append([a,b])

que = queue.Queue()
que.put(1)
result = [[-1,100000] for _ in range(N+1)]
result[1][1] = 0

while(True):
    if que.empty():
        break
    nex = que.get()
    
    for i in tree[nex]:
        if result[i[0]][0] == -1  :
            result[i[0]][0] = nex
            result[i[0]][1] = result[nex][1] +1

            
            que.put(i[0])
print(*result)

for i in range(2,N+1):
    for j in tree[i]:
        if result[j[0]][1] == result[i][1] -1:
            result[i][0] = j[0] 
result = result[2:]
if result.count(-1) !=0:
    print("No")
else :
    print("Yes")
    for i in result:
        print([i[0]])

Buggy submission (verdict: Runtime Error):
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append([b,a])
    tree[b].append([a,b])

que = queue.Queue()
que.put(1)
result = [[-1,100000] for _ in range(N+1)]
result[1][1] = 0

while(True):
    if que.empty():
        break
    nex = que.get()
    
    for i in tree[nex]:
        if result[i[0]][0] == -1 or result[i[0]][1] > result[nex][1] :
            result[i[0]][0] = nex
            result[i[0]][1] = result[nex][1] +1

            
            que.put(i[0])


result = result[2:]
if result.count(-1) != 0:
    print("No")
else :
    print("Yes")
    for i in result:
        print(i[0])

Buggy submission (verdict: Runtime Error):
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append([b,a])
    tree[b].append([a,b])

que = queue.Queue()
que.put(1)
result = [-1]*(N+1)
for i in range(len(tree[1])):
    tree[1][i][1] = 1
while(True):
    if que.empty():
        break
    nex = que.get()
    
    for i in tree[nex]:
        if result[i[0]] == -1 or result[i[1]] != -1:
            result[i[0]] = nex
            que.put(i[0])


result = result[2:]
if result.count(-1) != 0:
    print("No")
else :
    print("Yes")
    for i in result:
        print(i)

Buggy submission (verdict: Runtime Error):
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append([b,-1])
    tree[b].append([a,-1])

que = queue.Queue()
que.put(1)
result = [-1]*(N+1)
for i in range(len(tree[1])):
    tree[1][i][1] = 1
while(True):
    if que.empty():
        break
    nex = que.get()
    
    for i in tree[nex]:
        if result[i[0]] == -1:
            result[i[0]] = nex
            que.put(i[0])


result = result[2:]
if result.count(-1) != 0:
    print("No")
else :
    print("Yes")
    for i in result:
        print(i)