Buggy python submission (verdict: Runtime Error):
from collections import deque

def bfs(graph, visited, ss, g):
  queue = deque([ss])
  visited[ss] = 0
  while queue:
    s = queue.popleft()
    #　返り値に関する条件
    if visited[g] != -1 :
        return visited
    for new_s in graph[s] :
      if graph[new_s][s] == 1 and visited[new_s] == -1:
        #　移動回数の計算
        visited[new_s] = visited[s] + 1
        queue.append(new_s)
  return visited

n,m = map(int,input().split())
graph = [[] for j in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
 
d = [0]*n
for g in range(1,n) :
    visited = [-1]*n
    d[g] = bfs(graph, visited, 0, g)[g]

Fixed submission:
from collections import deque

def bfs(graph, visited, ss):
  queue = deque([ss])
  visited[ss] = 0
  ans = [0]*n
  while queue:
    s = queue.popleft()
    for new_s in graph[s] :
      if visited[new_s] == -1:
        #　移動回数の計算
        visited[new_s] = visited[s] + 1
        queue.append(new_s)
        ans[new_s] = s
  return ans

n,m = map(int,input().split())
graph = [[] for j in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

visited = [-1]*n
ans = bfs(graph, visited, 0)

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(graph, visited, ss, g):
  queue = deque([ss])
  visited[ss] = 0
  while queue:
    s = queue.popleft()
    #　返り値に関する条件
    if visited[g] != -1 :
        return visited
    for new_s in range(n) :
      if graph[new_s][s] == 1 and visited[new_s] == -1:
        #　移動回数の計算
        visited[new_s] = visited[s] + 1
        queue.append(new_s)
  return visited

n,m = map(int,input().split())
graph = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    graph[a-1][b-1] = 1
    graph[b-1][a-1] = 1
 
d = [0]*n
for g in range(1,n) :
    visited = [-1]*n
    d[g] = bfs(graph, visited, 0, g)[g]

maxd = max(d)
dpt = [[] for i in range(maxd+1)]
for i in range(maxd+1) :
    dpt[i] = [n for n, v in enumerate(d) if v == i]

if -1 in d :
    print('No')
else :
    print('Yes')
    for i in range(1,n) :
        print(dpt[d[i]-1][0]+1)

Fixed submission:
from collections import deque

def bfs(graph, visited, ss):
  queue = deque([ss])
  visited[ss] = 0
  ans = [0]*n
  while queue:
    s = queue.popleft()
    for new_s in graph[s] :
      if visited[new_s] == -1:
        #　移動回数の計算
        visited[new_s] = visited[s] + 1
        queue.append(new_s)
        ans[new_s] = s
  return ans

n,m = map(int,input().split())
graph = [[] for j in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

visited = [-1]*n
ans = bfs(graph, visited, 0)

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(graph, visited, ss, g):
  queue = deque([ss])
  visited[ss] = 0
  while queue:
    s = queue.popleft()
    #　返り値に関する条件
    if visited[g] != -1 :
        return visited
    for new_s in range(n) :
      if graph[new_s][s] == 1 and visited[new_s] == -1:
        #　移動回数の計算
        visited[new_s] = visited[s] + 1
        queue.append(new_s)
  return visited

n,m = map(int,input().split())
graph = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    graph[a-1][b-1] = 1
    graph[b-1][a-1] = 1
 
d = [0]*n
for g in range(1,n) :
    visited = [-1]*n
    d[g] = bfs(graph, visited, 0, g)[g]

maxd = max(d)
dpt = [[] for i in range(maxd+1)]
for i in range(maxd+1) :
    dpt[i] = [n for n, v in enumerate(d) if v == i]

if -1 in d :
    print('No')
else :
    print('Yes')
    for i in range(1,n) :
        print(dpt[d[i]-1][0]+1)

Fixed submission:
from collections import deque

def bfs(graph, visited, ss):
  queue = deque([ss])
  visited[ss] = 0
  ans = [0]*n
  while queue:
    s = queue.popleft()
    for new_s in graph[s] :
      if visited[new_s] == -1:
        #　移動回数の計算
        visited[new_s] = visited[s] + 1
        queue.append(new_s)
        ans[new_s] = s
  return ans

n,m = map(int,input().split())
graph = [[] for j in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

visited = [-1]*n
ans = bfs(graph, visited, 0)

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