Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
A=[]
B=[]
road=[[] for i in range(N)]
for i in range(N):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
visit=[0]*N

q=deque([0])
ans=[0]*N
visit[0]=1
def bfs(q):
  while(q):
    v=q.popleft()
    #print(v)
    for x in road[v]:
      if(visit[x]==0):
        q.append(x)
        #print(q)
        visit[x]=1
        ans[x]=v+1
        #print(x)
bfs(q)
print("Yes")
for i in range(N-1):
  print(ans[i+1])

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
A=[]
B=[]
road=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
visit=[0]*N

q=deque([0])
ans=[0]*N
visit[0]=1
def bfs(q):
  while(q):
    v=q.popleft()
    #print(v)
    for x in road[v]:
      if(visit[x]==0):
        q.append(x)
        #print(q)
        visit[x]=1
        ans[x]=v+1
        #print(x)
bfs(q)
print("Yes")
for i in range(N-1):
  print(ans[i+1])

Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
A=[]
B=[]
road=[[] for i in range(M)]
for i in range(M):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
visit=[0]*N

q=deque([0])
ans=[0]*N
visit[0]=1
def bfs(q):
  while(q):
    v=q.popleft()
    #print(v)
    for x in road[v]:
      if(visit[x]==0):
        q.append(x)
        #print(q)
        visit[x]=1
        ans[x]=v+1
        #print(x)
bfs(q)
print("Yes")
for i in range(N-1):
  print(ans[i+1])

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
A=[]
B=[]
road=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
visit=[0]*N

q=deque([0])
ans=[0]*N
visit[0]=1
def bfs(q):
  while(q):
    v=q.popleft()
    #print(v)
    for x in road[v]:
      if(visit[x]==0):
        q.append(x)
        #print(q)
        visit[x]=1
        ans[x]=v+1
        #print(x)
bfs(q)
print("Yes")
for i in range(N-1):
  print(ans[i+1])

Buggy python submission (verdict: Runtime Error):
from collections import deque
N,M=map(int,input().split())
A=[]
B=[]
road=[[] for i in range(M)]
for i in range(M):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
visit=[0]*N

q=deque([0])
ans=[0]*N
visit[0]=1
#print(road)
#print(road[1])
def bfs(q):
  while(q):
    v=q.popleft()
    #print(v)
    for x in road[v]:
      if(visit[x]==0):
        q.append(x)
        #print(q)
        visit[x]=1
        ans[x]=v+1
        #print(x)
bfs(q)
print("Yes")
for i in range(N-1):
  print(ans[i+1])

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
A=[]
B=[]
road=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
visit=[0]*N

q=deque([0])
ans=[0]*N
visit[0]=1
def bfs(q):
  while(q):
    v=q.popleft()
    #print(v)
    for x in road[v]:
      if(visit[x]==0):
        q.append(x)
        #print(q)
        visit[x]=1
        ans[x]=v+1
        #print(x)
bfs(q)
print("Yes")
for i in range(N-1):
  print(ans[i+1])