Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
lst = []
for i in range(m):
  x,y = map(int,input().split())
  lst.append([x,y]) 
from collections import deque
d = ['t']*n
d[0] = 0
que = deque([1])
while que:
  p = que.popleft()
  for j in range(m):
    if lst[j][0] == p:
      q = lst[j][1]
      if d[q-1] == 't':
        d[q-1] = p
        que.append(q)
    if lst[j][1] == p:
      q = lst[j][0]
      if d[q-1] == 't':
        d[q-1] = p   
        que.append(q)
print('Yes')        
for i in range(1,n):
  print(d[i])
        

Fixed submission:
from collections import deque

n, m = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    a[x - 1].append(y - 1)
    a[y - 1].append(x - 1)
c = [0] * n
que = deque([])
que.append(0)
while len(que) > 0:
    e = que.popleft()
    for i in a[e]:
        if c[i] > 0:
            continue
        c[i] = e + 1
        que.append(i)
print("Yes")
for i in range(1, n):
    print(c[i])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
lst = []
for i in range(m):
  x,y = map(int,input().split())
  lst.append([x,y]) 
from collections import deque
d = ['t']*n
d[0] = 0
que = deque([1])
while que:
  p = que.popleft()
  for j in range(m):
    if lst[j][0] == p:
      q = lst[j][1]
      if d[q-1] == 't':
        d[q-1] = p
        que.append(q)
    if lst[j][1] == p:
      q = lst[j][0]
      if d[q-1] == 't':
        d[q-1] = p   
        que.append(q)
print('Yes')        
for i in range(1,n):
  print(d[i])
        
        

Fixed submission:
from collections import deque

n, m = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    a[x - 1].append(y - 1)
    a[y - 1].append(x - 1)
c = [0] * n
que = deque([])
que.append(0)
while len(que) > 0:
    e = que.popleft()
    for i in a[e]:
        if c[i] > 0:
            continue
        c[i] = e + 1
        que.append(i)
print("Yes")
for i in range(1, n):
    print(c[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
route = [list(map(int,input().split())) for i in range(M)]

arrow = [0]*(N-1)
list1 = [1]
list_total = [1]
s = 0
for j in range(N):
  if s == N-1:
    break
  
  list2 = []
  for x in list1:
    for i in range(M):
      if route[i][0] == x and route[i][1] not in list_total:
        arrow[route[i][1]-2] = x
        list2.append(route[i][1])
        list_total.append(route[i][1])
        s = s+1
      if route[i][1] == x and route[i][0] not in list_total:
        arrow[route[i][0]-2] = x
        list2.append(route[i][0])
        list_total.append(route[i][0])
        s = s+1
      
  list1 = list2
print('Yes')
for y in arrow:
  print(y)



Fixed submission:
from collections import deque

n, m = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    a[x - 1].append(y - 1)
    a[y - 1].append(x - 1)
c = [0] * n
que = deque([])
que.append(0)
while len(que) > 0:
    e = que.popleft()
    for i in a[e]:
        if c[i] > 0:
            continue
        c[i] = e + 1
        que.append(i)
print("Yes")
for i in range(1, n):
    print(c[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
route = [list(map(int,input().split())) for i in range(M)]

arrow = [0]*(N-1)
list1 = [1]
list_total = [1]
s = 0
for j in range(N):
  if s == N-1:
    break
  
  list2 = []
  for x in list1:
    for i in range(M):
      if route[i][0] == x and route[i][1] not in list_total:
        arrow[route[i][1]-2] = x
        list2.append(route[i][1])
        list_total.append(route[i][1])
        s = s+1
      if route[i][1] == x and route[i][0] not in list_total:
        arrow[route[i][0]-2] = x
        list2.append(route[i][0])
        list_total.append(route[i][0])
        s = s+1
      
  list1 = list2
print('Yes')
for y in arrow:
  print(y)



Fixed submission:
from collections import deque

n, m = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    a[x - 1].append(y - 1)
    a[y - 1].append(x - 1)
c = [0] * n
que = deque([])
que.append(0)
while len(que) > 0:
    e = que.popleft()
    for i in a[e]:
        if c[i] > 0:
            continue
        c[i] = e + 1
        que.append(i)
print("Yes")
for i in range(1, n):
    print(c[i])