Buggy python submission (verdict: Runtime Error):
n,m=list(map(int,input().split()))
road=[[] for i in range(m)]
#隣接行列表現だとo(n^2)で間に合わないので隣接リスト表現でいく
for i in range(m):
  a,b=list(map(int,input().split()))
  road[a-1].append(b)
  road[b-1].append(a)
from collections import deque
q=deque([1])
check=[0 for i in range(n)]
check[0]=1
ans=[0 for i in range(n)]
while len(q)>0:
  p=q.popleft()
  for i in range(len(road[p-1])):
    if check[road[p-1][i]-1]==0:
      q.append(road[p-1][i])
      check[road[p-1][i]-1]=1
      ans[road[p-1][i]-1]=p
print("Yes")

for i in range(1,n):
  print(ans[i])
  

      
  
  

Fixed submission:
n,m=list(map(int,input().split()))
road_input=[]
for i in range(m):
    road_input.append(list(map(int,input().split())))

#隣接リスト
road=[[] for i in range(n+1)]
for i in range(m):
    road[road_input[i][0]].append(road_input[i][1])
    road[road_input[i][1]].append(road_input[i][0])

from collections import deque
q=deque([1])
ans=[-1 for i in range(n)]
while len(q)>0:
  p=q.popleft()
  for i in road[p]:
    if ans[i-1]== -1:
      ans[i-1]=p
      q.append(i)

print("Yes")
for j in range(1,n):
    print(ans[j])

Buggy python submission (verdict: Time Limit Exceeded):
#問題文に連結と書いてあるのでどの部屋も互いに行き来できる
#自分がきたところを記録する幅優先探索をすればいい
n,m=list(map(int,input().split()))
#道を二次元リストで表す
road=[[0 for i in range(n)] for j in range(n)]
for i in range(m):
  a,b=list(map(int,input().split()))
  road[a-1][b-1]=1
  road[b-1][a-1]=1
#幅優先探索
from collections import deque
q=deque([1])
ans=[0 for i in range(n)]
check=[0 for i in range(n)]
check[0]=1
while len(q)>0: 
  p=q.popleft()
  for j in range(n):
    if road[p-1][j]!=0 and check[j]==0:
      q.append(j+1)
      check[j]=1
      ans[j]=p
print("Yes")
for i in range(1,n):
  print(ans[i])
  

  

Fixed submission:
n,m=list(map(int,input().split()))
road_input=[]
for i in range(m):
    road_input.append(list(map(int,input().split())))

#隣接リスト
road=[[] for i in range(n+1)]
for i in range(m):
    road[road_input[i][0]].append(road_input[i][1])
    road[road_input[i][1]].append(road_input[i][0])

from collections import deque
q=deque([1])
ans=[-1 for i in range(n)]
while len(q)>0:
  p=q.popleft()
  for i in road[p]:
    if ans[i-1]== -1:
      ans[i-1]=p
      q.append(i)

print("Yes")
for j in range(1,n):
    print(ans[j])

Buggy python submission (verdict: Time Limit Exceeded):
#問題文に連結と書いてあるのでどの部屋も互いに行き来できる
#自分がきたところを記録する幅優先探索をすればいい
n,m=list(map(int,input().split()))
road=[[0 for i in range(n)] for j in range(n)]
ab=[]
for i in range(m):
  a,b=list(map(int,input().split()))
  road[a-1][b-1]=1
  road[b-1][a-1]=1
from collections import deque
q=deque([1])
ans=[0 for i in range(n)]
check=[0 for i in range(n)]
check[0]=1
while len(q)>0: 
  
  p=q.popleft()
  for j in range(n):
    if road[p-1][j]!=0 and check[j]==0:
      q.append(j+1)
      road[p-1][j]=0
      road[j][p-1]=0
      check[j]=1
      ans[j]=p
print("Yes")
for i in range(1,n):
  print(ans[i])
  

  

Fixed submission:
n,m=list(map(int,input().split()))
road_input=[]
for i in range(m):
    road_input.append(list(map(int,input().split())))

#隣接リスト
road=[[] for i in range(n+1)]
for i in range(m):
    road[road_input[i][0]].append(road_input[i][1])
    road[road_input[i][1]].append(road_input[i][0])

from collections import deque
q=deque([1])
ans=[-1 for i in range(n)]
while len(q)>0:
  p=q.popleft()
  for i in road[p]:
    if ans[i-1]== -1:
      ans[i-1]=p
      q.append(i)

print("Yes")
for j in range(1,n):
    print(ans[j])