Buggy python submission (verdict: Time Limit Exceeded):
import networkx as nx
N, M = map(int, input().split())

G = nx.Graph()
G.add_nodes_from(range(1, N+1))
for _ in range(M):
  a, b = map(int, input().split())
  G.add_edge(a, b)

dist = nx.shortest_path_length(G, target=1)
print('Yes')
for i in range(2, N+1):
  print(min((dist[j], j) for j in nx.all_neighbors(G, i))[1])
    





Fixed submission:
import networkx as nx
N, M = map(int, input().split())

G = nx.Graph()

G.add_edges_from(tuple(map(int, input().split())) for _ in range(M))

dist = nx.shortest_path_length(G, target=1)
print('Yes')
for i in range(2, N+1):
  print(min((dist[j], j) for j in nx.all_neighbors(G, i))[1])

Buggy python submission (verdict: Time Limit Exceeded):
import networkx as nx
N, M = map(int, input().split())

G = nx.Graph()
G.add_nodes_from(range(1, N+1))
for _ in range(M):
  a, b = map(int, input().split())
  G.add_edge(a, b)

paths = nx.shortest_path(G, target=1)
print('Yes')
for i in range(2, N+1):
  print(paths[i][1])





Fixed submission:
import networkx as nx
N, M = map(int, input().split())

G = nx.Graph()

G.add_edges_from(tuple(map(int, input().split())) for _ in range(M))

dist = nx.shortest_path_length(G, target=1)
print('Yes')
for i in range(2, N+1):
  print(min((dist[j], j) for j in nx.all_neighbors(G, i))[1])

Buggy python submission (verdict: Time Limit Exceeded):
import queue

N, M = [int(x) for x in input().split(' ')]
A = []
B = []
connected = [set() for _ in range(N)]
for _ in range(M):
  a, b = [int(x) - 1 for x in input().split(' ')]
  A.append(a)
  B.append(b)
  connected[a].add(b)
  connected[b].add(a)
  

print('Yes')

ans = [-1] * N
dist = [N+100] * N
dist[0] = 0
next_all = queue.Queue(N)
next_all.put(0)
processed = set()

while not next_all.empty():
  n = next_all.get()
  processed.add(n)
  
  pre = min([(dist[c], c) for c in connected[n]])
  dist[n] = pre[0] + 1 if pre[0] < N else 0
  ans[n] = pre[1]
  for c in connected[n]:
    if c not in processed:
      next_all.put(c)
# print(dist)
for a in ans[1:]:
  print(a+1)



Fixed submission:
import networkx as nx
N, M = map(int, input().split())

G = nx.Graph()

G.add_edges_from(tuple(map(int, input().split())) for _ in range(M))

dist = nx.shortest_path_length(G, target=1)
print('Yes')
for i in range(2, N+1):
  print(min((dist[j], j) for j in nx.all_neighbors(G, i))[1])

Buggy python submission (verdict: Time Limit Exceeded):
import queue

N, M = [int(x) for x in input().split(' ')]
A = []
B = []
connected = [set() for _ in range(N)]
for _ in range(M):
  a, b = [int(x) - 1 for x in input().split(' ')]
  A.append(a)
  B.append(b)
  connected[a].add(b)
  connected[b].add(a)
  

print('Yes')

ans = [-1] * N
dist = [N+100] * N
dist[0] = 0
next_all = queue.Queue(N)
next_all.put(0)

while not next_all.empty():
  n = next_all.get()
  # print(n, dist, ans)
  if ans[n] >= 0:
    continue
  pre = min([(dist[c], c) for c in connected[n]])
  dist[n] = pre[0] + 1 if pre[0] < N else 0
  ans[n] = pre[1]
  for c in connected[n]:
    if ans[c] < 0:
      next_all.put(c)
# print(dist)
for a in ans[1:]:
  print(a+1)



Fixed submission:
import networkx as nx
N, M = map(int, input().split())

G = nx.Graph()

G.add_edges_from(tuple(map(int, input().split())) for _ in range(M))

dist = nx.shortest_path_length(G, target=1)
print('Yes')
for i in range(2, N+1):
  print(min((dist[j], j) for j in nx.all_neighbors(G, i))[1])