Buggy python submission (verdict: Runtime Error):
import sys

N, M = map(int, sys.stdin.readline().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

tree = [[] for _ in range(N + 1)]
for a, b in AB:
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

# 深さ優先探索
sign_list = [[] for _ in range(N)]
visited = [0] * N
visited[0] = 1

def dfs(tree, pos):
    visited[pos] = 1
    children = []
    for r in tree[pos]:
        if visited[r] == 0:
            children.append(r)
    for c in children:
        sign_list[c] = pos + 1
        dfs(tree, c)

dfs(tree, 0)

for i in range(1, N):
  print('Yes')
  print(sign_list[i])


Fixed submission:
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

graph = [[] for _ in range(N)]

for a, b in AB:
    graph[a - 1].append(b)
    graph[b - 1].append(a)
    
queue = deque()
visited = [0] * N
sign_list = [0] * N 

queue.append(1)
visited[0] = 1

while queue:
    room = queue.popleft()
    next_rooms = graph[room - 1]
    for r in next_rooms:
        if visited[r - 1] == 0:
            queue.append(r)
            sign_list[r - 1] = room
            visited[r - 1] = 1

yes = True
for s in sign_list[1:]:
    if s == 0:
        yes = False

if yes:
    print("Yes")
    for s in sign_list[1:]:
        print(s)
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
import sys

N, M = map(int, sys.stdin.readline().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

tree = [[] for _ in range(N + 1)]
for a, b in AB:
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

# 深さ優先探索
sign_list = [[] for _ in range(N)]
visited = [0] * N
visited[0] = 1

def dfs(tree, pos):
    visited[pos] = 1
    children = []
    for r in tree[pos]:
        if visited[r] == 0:
            children.append(r)
    for c in children:
        sign_list[c] = pos + 1
        dfs(tree, c)

dfs(tree, 0)

for i in range(1, N):
  	print('Yes')
    print(sign_list[i])


Fixed submission:
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

graph = [[] for _ in range(N)]

for a, b in AB:
    graph[a - 1].append(b)
    graph[b - 1].append(a)
    
queue = deque()
visited = [0] * N
sign_list = [0] * N 

queue.append(1)
visited[0] = 1

while queue:
    room = queue.popleft()
    next_rooms = graph[room - 1]
    for r in next_rooms:
        if visited[r - 1] == 0:
            queue.append(r)
            sign_list[r - 1] = room
            visited[r - 1] = 1

yes = True
for s in sign_list[1:]:
    if s == 0:
        yes = False

if yes:
    print("Yes")
    for s in sign_list[1:]:
        print(s)
else:
    print("No")

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

N, M = map(int, sys.stdin.readline().split())

def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    sign_list = [[0] for _ in range(N - 1)]
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
               if d[j] == d[v]+cost[v][j]:
                   sign_list[j - 1] = v + 1
               
    return sign_list

cost = [[float("inf") for i in range(N)] for i in range(N)]

for i in range(M):
    x,y = map(int,input().split())
    cost[x - 1][y - 1] = 1
    cost[y - 1][x - 1] = 1
    
sign_list = dijkstra(0,N,M,cost)
flag = True
for i in range(N - 1):
    if sign_list[i] == 0:
        flag = False
        break

if flag:
    print('Yes')
    for i in range(N - 1):
        print(sign_list[i])
else:
    print('No')

Fixed submission:
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

graph = [[] for _ in range(N)]

for a, b in AB:
    graph[a - 1].append(b)
    graph[b - 1].append(a)
    
queue = deque()
visited = [0] * N
sign_list = [0] * N 

queue.append(1)
visited[0] = 1

while queue:
    room = queue.popleft()
    next_rooms = graph[room - 1]
    for r in next_rooms:
        if visited[r - 1] == 0:
            queue.append(r)
            sign_list[r - 1] = room
            visited[r - 1] = 1

yes = True
for s in sign_list[1:]:
    if s == 0:
        yes = False

if yes:
    print("Yes")
    for s in sign_list[1:]:
        print(s)
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
import sys

N, M = map(int, sys.stdin.readline().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

tree = [[] for _ in range(N + 1)]
for a, b in AB:
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

# 深さ優先探索
sign_list = [[] for _ in range(N)]
visited = [0] * N
visited[0] = 1

def dfs(tree, pos):
    visited[pos] = 1
    children = []
    for r in tree[pos]:
        if visited[r] == 0:
            children.append(r)
    for c in children:
        sign_list[c] = pos + 1
        dfs(tree, c)

dfs(tree, 0)

for i in range(1, N):
    print(sign_list[i])

Fixed submission:
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

graph = [[] for _ in range(N)]

for a, b in AB:
    graph[a - 1].append(b)
    graph[b - 1].append(a)
    
queue = deque()
visited = [0] * N
sign_list = [0] * N 

queue.append(1)
visited[0] = 1

while queue:
    room = queue.popleft()
    next_rooms = graph[room - 1]
    for r in next_rooms:
        if visited[r - 1] == 0:
            queue.append(r)
            sign_list[r - 1] = room
            visited[r - 1] = 1

yes = True
for s in sign_list[1:]:
    if s == 0:
        yes = False

if yes:
    print("Yes")
    for s in sign_list[1:]:
        print(s)
else:
    print("No")