Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,M=list(map(int,input().split()))
l=[[] for i in range(N)]
l2=np.zeros(N-1)
import sys
l_l=[i.rsplit() for i in sys.stdin.readlines()]
l_l = [list(map(int,i)) for i in l_l]
for i in l_l:
   l[i[0]-1].append(i[1])
   l[i[1]-1].append(i[0])
from collections import deque
que=deque([1])
after=deque()
que_append=que.append
after_append=after.append
while que != deque([]):
   X=que.popleft()
   after_append(X)
   for i in l[X-1]:
      if i in after:
         continue
      if i in que:
         continue
      que_append(i)
      np.put(l2,[i-2],X)
if len(after) == N:
   print("Yes")
   for i in l2:
      print(int(i))
else:
   print("No")

Fixed submission:
from collections import deque
def bfs(graph,N):
   que=deque([0])
   visited=[0]*N
   visited[0]=1
   while que:
      node=que.popleft()
      for i in graph[node]:
         if not visited[i]:
            visited[i]=node+1
            que.append(i)
   return visited
N,M= list(map(int,input().split()))
l=[[] for i in range(N)]
for i in range(M):
   a,b=list(map(int,input().split()))
   a-=1;b-=1
   l[a].append(b)
   l[b].append(a)
ans=bfs(l,N)[1:]
if all(ans):
   print("Yes")
   print(*ans,sep="\n")
else:
   print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N,M=list(map(int,input().split()))
l=[[] for i in range(N)]
l2=[0]*(N-1)
import sys
l_l=[i.rsplit() for i in sys.stdin.readlines()]
l_l = [list(map(int,i)) for i in l_l]
for i in l_l:
   l[i[0]-1].append(i[1])
   l[i[1]-1].append(i[0])
from collections import deque
que=deque([1])
after=deque()
que_append=que.append
after_append=after.append
while que != deque([]):
   X=que.popleft()
   after_append(X)
   for i in l[X-1]:
      if i in after:
         continue
      if i in que:
         continue
      que_append(i)
      l2[i-2]=X
if len(after) == N:
   print("Yes")
   for i in l2:
      print(i)
else:
   print("No")

Fixed submission:
from collections import deque
def bfs(graph,N):
   que=deque([0])
   visited=[0]*N
   visited[0]=1
   while que:
      node=que.popleft()
      for i in graph[node]:
         if not visited[i]:
            visited[i]=node+1
            que.append(i)
   return visited
N,M= list(map(int,input().split()))
l=[[] for i in range(N)]
for i in range(M):
   a,b=list(map(int,input().split()))
   a-=1;b-=1
   l[a].append(b)
   l[b].append(a)
ans=bfs(l,N)[1:]
if all(ans):
   print("Yes")
   print(*ans,sep="\n")
else:
   print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N,M=list(map(int,input().split()))
l=[[] for i in range(N)]
l2=[0]*(N-1)
for i in range(M):
   A,B= list(map(int,input().split()))
   l[A-1].append(B)
   l[B-1].append(A)
from collections import deque
que=deque([1])
after=deque()
while que != deque([]):
   X=que.popleft()
   after.append(X)
   for i in l[X-1]:
      if i in after:
         continue
      if i in que:
         continue
      que.append(i)
      l2[i-2]=X
if len(after) == N:
   print("Yes")
   for i in l2:
      print(i)
else:
   print("No")

Fixed submission:
from collections import deque
def bfs(graph,N):
   que=deque([0])
   visited=[0]*N
   visited[0]=1
   while que:
      node=que.popleft()
      for i in graph[node]:
         if not visited[i]:
            visited[i]=node+1
            que.append(i)
   return visited
N,M= list(map(int,input().split()))
l=[[] for i in range(N)]
for i in range(M):
   a,b=list(map(int,input().split()))
   a-=1;b-=1
   l[a].append(b)
   l[b].append(a)
ans=bfs(l,N)[1:]
if all(ans):
   print("Yes")
   print(*ans,sep="\n")
else:
   print("No")