Problem p02678 (python)

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

michi=[-1]*(n)
michi[0]=0
heya=[]


for i in range(m):
    b[a[i][0]-1].append(a[i][1])
    b[a[i][1]-1].append(a[i][0])



heya.append(1)


while len(heya):
    now=heya.pop(0)-1
    
    for i in range(len(b[now])):
        if michi[b[now][i]-1] == -1:
            heya.append(b[now][i])
            michi[b[now][i]-1] = now+1
print("Yes")
for i in range(1,n):
    print(michi[i])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(m)]
ikeruheya = [[] for i in range(n)]
ans = [0]*(n+1)

ans[0]=1
ans[1]=1
for i in range(m):
    ikeruheya[a[i][0]-1].append(a[i][1])
    ikeruheya[a[i][1]-1].append(a[i][0])


next=[1]
count = 1
while len(next)!=0:
    imaheya = next.pop(0)
    for i in range(len(ikeruheya[imaheya-1])):
        if ans[ikeruheya[imaheya-1][j]]==0:
            ans[ikeruheya[imaheya-1][j]]= imaheya             
            next.append(ikeruheya[imaheya-1][j])
            #ikeruheya[[imaheya-1][j]-1].remove(imaheya)
        

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

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(m)]
ikeruheya = [[] for i in range(n)]
ans = [0]*(n+1)
check = [0]*n
check[0]=1
for i in range(m):
    ikeruheya[a[i][0]-1].append(a[i][1])
    ikeruheya[a[i][1]-1].append(a[i][0])
print(ikeruheya)
    
next=[1]
count = 1
while len(next) != 0 and count <= n:
    imaheya = next.pop(0)
    for j in range(len(ikeruheya[imaheya-1])):
        print(ikeruheya[imaheya-1])
        if check[ikeruheya[imaheya-1][j]-1]==0:
            ans[ikeruheya[imaheya-1][j]]= imaheya 
            check[ikeruheya[imaheya-1][j]-1] = 1
            next.append(ikeruheya[imaheya-1][j])
            count += 1
            
print("Yes")
for i in range(2, n+1):
    print(ans[i])

print(check)
print(count)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range m]
ikeruheya = [[] for i in range n]
ans = []
check = [0]*n

for i in range(m):
    ikeruheya[a[i][0]].append[a[i][1]]
    ikeruheya[a[i][1]].append[a[i][0]]
    
next=[0]

while len(next) != 0:
    imaheya = next.pop(0)
    for j in range(len(ikeruheya[imaheya])):
        if check(ikeruheya[imaheya][j])==0:
            ans[ikeruheya[imaheya][j]]= j + 1
            check[ikeruheya[imaheya][j]-1] = 1
            next.append(ikeruheya[imaheya][j]-1)
for i in range(2, n+1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a=[list(map(int, input().split())) for i in range(n)]
b=[[0]* n for j in range(n)] 
bb=[]
for i in range(n-1):
    bb.append(i)
c=[]
d=[0]*n-1
for i in range(n):
    for j in range(n):
        b[a[i][0][a[i][1]] = a[i][1]
        b[a[i][1]][a[i][0]] = a[i][0]
while len(bb)!=0:
    for i in range(n):
        if b[i][j]==1:
            c.append(b[i][j])
            bb.deque(b[i][j])
            d[b[i][j]]=i+1
            print(b[i][j]+1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a=[list(map(int, input().split())) for i in range(n)]
b=[[0]* n for j in range(n)] 
bb=[]
for i in range(n-1):
    bb.append(i)
c=[]
d=[0]*n-1
for i in range(n):
    for j in range(n):
        b[a[i][0][a[i][1]] = a[i][1]
        b[a[i][1]][a[i][0]] = a[i][0]
while len(bb)!=0:
    for i in range(n):
        if b[i][j]=-1:
            c.append(b[i][j])
            bb.deque(b[i][j])
            d[b[i][j]]=i+1
            print(b[i][j]+1)