Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m=map(int,input().split())
cost = [[float("inf") for i in range(n)] for i in range(n)] 
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[None]*n    

que=deque([0])
while que:
    v=que.pop()
    for i in to[v]:
        if(dist[i] is None):
            dist[i]=v+1
            que.appendleft(i)
        
print("Yes")
for i in dist[1:]:
    print(i)    


Fixed submission:
from collections import deque
n,m=map(int,input().split())
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[None]*n    

que=deque([0])
while que:
    v=que.pop()
    for i in to[v]:
        if(dist[i] is None):
            dist[i]=v+1
            que.appendleft(i)
        
print("Yes")
for i in dist[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m=map(int,input().split())
cost = [[float("inf") for i in range(n)] for i in range(n)] 
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[1000000]*n    

que=deque([0])
while que:
    v=que.pop()
    for i in to[v]:
        if(dist[i] is 1000000):
            dist[i]=v+1
            que.appendleft(i)
        
print("Yes")
for i in dist[1:]:
    print(i)    


Fixed submission:
from collections import deque
n,m=map(int,input().split())
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[None]*n    

que=deque([0])
while que:
    v=que.pop()
    for i in to[v]:
        if(dist[i] is None):
            dist[i]=v+1
            que.appendleft(i)
        
print("Yes")
for i in dist[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m=map(int,input().split())
cost = [[float("inf") for i in range(n)] for i in range(n)] 
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[1000000]*n    

que=deque([])
que.append(0)
while(len(que)):
    v=que.popleft()
    for i in to[v]:
        if(dist[i] is 1000000):
            dist[i]=v+1
            que.append(i)
        
print("Yes")
for i in dist[1:]:
    print(i)    


Fixed submission:
from collections import deque
n,m=map(int,input().split())
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[None]*n    

que=deque([0])
while que:
    v=que.pop()
    for i in to[v]:
        if(dist[i] is None):
            dist[i]=v+1
            que.appendleft(i)
        
print("Yes")
for i in dist[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())

cost = [[float("inf") for i in range(n)] for i in range(n)] 
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[1000000]*n    

que=[]
que.append(0)
while(len(que)):
    v=que.pop(0)
    for i in to[v]:
        if(dist[i] is 1000000):
            dist[i]=v+1
            que.append(i)
        
print("Yes")
for i in dist[1:]:
    print(i)    


Fixed submission:
from collections import deque
n,m=map(int,input().split())
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[None]*n    

que=deque([0])
while que:
    v=que.pop()
    for i in to[v]:
        if(dist[i] is None):
            dist[i]=v+1
            que.appendleft(i)
        
print("Yes")
for i in dist[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())

cost = [[float("inf") for i in range(n)] for i in range(n)] 
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[0]*n    
flag=[False]*n
flag[0]=True
que=[]
que.append(0)
while(False in flag):
    v=que.pop(0)
    for i in to[v]:
        if(flag[i]==False):
            dist[i]=v+1
            flag[i]=True
            que.append(i)
        


print("Yes")
for i in dist[1:]:
    print(i)    


Fixed submission:
from collections import deque
n,m=map(int,input().split())
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[None]*n    

que=deque([0])
while que:
    v=que.pop()
    for i in to[v]:
        if(dist[i] is None):
            dist[i]=v+1
            que.appendleft(i)
        
print("Yes")
for i in dist[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n,m=map(int,input().split())

cost = [[float("inf") for i in range(n)] for i in range(n)] 

for i in range(m):
    x,y = map(int,input().split())
    cost[x-1][y-1] = 1
    cost[y-1][x-1] = 1

dist=[0]*n    
flag=[False]*n
flag[0]=True
que=[]
que.append(0)
while(False in flag):
    v=que.pop(0)
    tmp=copy.deepcopy(que)
    for i in range(n):
        if(cost[v][i]==1 and flag[i]==False):
            dist[i]=v+1
            flag[i]=True
            que.append(i)
    if(tmp==que):
        print("No")
        exit()
print("Yes")
for i in dist[1:]:
    print(i)    


Fixed submission:
from collections import deque
n,m=map(int,input().split())
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[None]*n    

que=deque([0])
while que:
    v=que.pop()
    for i in to[v]:
        if(dist[i] is None):
            dist[i]=v+1
            que.appendleft(i)
        
print("Yes")
for i in dist[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())

def dijkstra(s,n,w,cost):
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    past=[[] for i in range(n)] 
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
            if(d[j]>d[v]+cost[v][j]):
                d[j]=d[v]+cost[v][j]
                past[j].append(v)
            else:
                d[j]=d[j]
                # past[j].append(j)



    return d,used,past

cost = [[float("inf") for i in range(n)] for i in range(n)] 

for i in range(m):
    x,y = map(int,input().split())
    cost[x-1][y-1] = 1
    cost[y-1][x-1] = 1

ans,used,past= dijkstra(0,n,m,cost)
if(False in used):print("No")
else:
    print("Yes")
    for i in past[1:]:
        print(i[0]+1)

Fixed submission:
from collections import deque
n,m=map(int,input().split())
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[None]*n    

que=deque([0])
while que:
    v=que.pop()
    for i in to[v]:
        if(dist[i] is None):
            dist[i]=v+1
            que.appendleft(i)
        
print("Yes")
for i in dist[1:]:
    print(i)