Problem p02678 (python)

Fixed submission:
#inport
import sys
import numpy as np
from collections import deque


#input
N,M = [int(x) for x in sys.stdin.readline().split()]
g = [[] for _ in range(N+1)]

for _ in range(M):
    a, b = [int(x) for x in sys.stdin.readline().split()]
    g[a].append(b)
    g[b].append(a)



quetmp = deque([1])
d = [None] * (N+1)
d[1] = 0
num_crew = 1
while quetmp:
    v = quetmp.popleft()
    for i in g[v]:
        if d[i] is None:
            d[i] = v
            quetmp.append(i)
            num_crew = num_crew + 1

if num_crew == N:
    print('Yes')
    for i in range(N-1):
        print(d[i+2])
else:
    print('No')

Buggy submission (verdict: Runtime Error):
#inport
import sys
import numpy as np
from collections import deque


#input
N,M = [int(x) for x in sys.stdin.readline().split()]
g = [[] for _ in range(M)]

for _ in range(M):
    a, b = [int(x) for x in sys.stdin.readline().split()]
    g[a].append(b)
    g[b].append(a)



quetmp = deque([1])
d = [None] * (N+1)
d[1] = 0
num_crew = 1
while quetmp:
    v = quetmp.popleft()
    for i in g[v]:
        print(i)
        print(d[i])
        if d[i] is None:
            d[i] = v
            quetmp.append(i)
            num_crew = num_crew + 1

if num_crew == N:
    print('Yes')
    for i in range(N-1):
        print(d[i+1])
else:
    print('No')

Buggy submission (verdict: Runtime Error):
#inport
import sys
import numpy as np

#input
N,M = map(int, sys.stdin.readline().split())
P = [list(map(int, sys.stdin.readline().split())) for i in range(M)]

#shori
##初期化
P = np.array(P)     
ans = np.zeros((N,2))
tmp_latest = np.zeros(1)
tmp_latest_tmp = np.zeros(1)
tmp_latest[0] = 1
pos_latest = 0
num_latest = 1
ans[0][1] = 1 #部屋1をてがかりありに
flg_pos = 1
flg_fale = 0
num_crew = 1
num_left_room = N-1
left_room = np.zeros(N)

for i in range(N):
    ans[i][0] = i + 1

while num_crew < N:
    if flg_pos == 0:
        flg_fale = 1
        break

    flg_pos = 0
    for i in range(num_latest):
        tmp_room_num = tmp_latest[i]
        tmp_root = P[np.any( P == int(tmp_room_num), axis = 1)]
        root_loop_n = int(np.size(tmp_root)/2)
        for j in range(root_loop_n):
            if tmp_root[j][0]==tmp_latest[i]:
                if(ans[tmp_root[j][1]-1][1]==0):
                    tmp_latest_tmp = np.insert(tmp_latest_tmp, 0, tmp_root[j][1])
                    ans[tmp_root[j][1]-1][1] = tmp_latest[i]
                    num_crew = num_crew + 1
                    flg_pos = 1
            elif tmp_root[j][1]==tmp_latest[i]:
                if(ans[tmp_root[j][0]-1][1]==0):
                    tmp_latest_tmp = np.insert(tmp_latest_tmp, 0, tmp_root[j][0])
                    ans[tmp_root[j][0]-1][1] = tmp_latest[i]
                    num_crew = num_crew + 1
                    flg_pos = 1               
        P = np.delete(P, np.where(P == int(tmp_room_num))[0], axis = 0)

    #Nループ終了時にtmp_latestを更新
    tmp_latest = np.insert(tmp_latest, num_latest, tmp_latest_tmp)
    for j in range(num_latest):
        tmp_latest = np.delete(tmp_latest,0)
    num_latest = np.size(tmp_latest)
    tmp_latest = np.delete(tmo_latest,num_latest-1)
    num_latest = np.size(tmp_latest)
    tmp_latest_tmp = np.zeros(1)

    
if flg_fale == 0:
    print('Yes')
    for i in range(N-1):
        print(int(ans[i+1][1]))
else:
    print('No')