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

def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())


N, M = mapint_inp()
ABs = [list(mapint_inp()) for _ in range(N)]

adjacency_matrix = [[]*(N+1) for _ in range(N+1)]

for AB in ABs:
    A, B = AB
    # 隣接しているA,Bに関して、
    # A番目のリストに値Bを、B番目のリストに値Aを追加して
    # 隣接を管理する
    adjacency_matrix[A].append(B)
    adjacency_matrix[B].append(A)

result = [0]*(N+1)

q = deque([1])
while q:
    now = q.popleft()
    for i in adjacency_matrix[now]:
        if result[i] == 0:
            result[i] == now
            q.append(i)

print("Yes")
print('\n'.join(str(i) for i in result[2:]))

Fixed submission:
from collections import deque

def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())


n, m = mapint_inp()
graph = [[] for _ in range(n)]
ans = [0]*n

for _ in range(m):
    a, b = mapint_inp()
    a -= 1; b -= 1
    graph[a].append(b)
    graph[b].append(a) 

q = deque([0])
visited = [False]*n
visited[0] = True
while q:
    now = q.popleft()
    for i in graph[now]:
        if visited[i]: continue
        visited[i] = True
        ans[i] = now
        q.append(i)

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

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

def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())


N, M = mapint_inp()
ABs = [list(mapint_inp()) for _ in range(N)]

adjacency_matrix = [[0]*(N+1) for _ in range(N+1)]

for AB in ABs:
    A, B = AB
    # 隣接しているA,Bに関して、
    # A番目のリストに値Bを、B番目のリストに値Aを追加して
    # 隣接を管理する
    adjacency_matrix[A].append(B)
    adjacency_matrix[B].append(A)

result = [0]*(N+1)

q = deque([1])
while q:
    now = q.popleft()
    for i in adjacency_matrix[now]:
        if result[i] == 0:
            result[i] == now
            q.append(i)

print("Yes")
print('\n'.join(str(i) for i in result[2:]))

Fixed submission:
from collections import deque

def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())


n, m = mapint_inp()
graph = [[] for _ in range(n)]
ans = [0]*n

for _ in range(m):
    a, b = mapint_inp()
    a -= 1; b -= 1
    graph[a].append(b)
    graph[b].append(a) 

q = deque([0])
visited = [False]*n
visited[0] = True
while q:
    now = q.popleft()
    for i in graph[now]:
        if visited[i]: continue
        visited[i] = True
        ans[i] = now
        q.append(i)

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

Buggy python submission (verdict: Time Limit Exceeded):
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())


N, M = mapint_inp()

adjm = [[0]*(N+1) for _ in range(N+1)]

for i in range(M):
    A, B = mapint_inp()
    adjm[A][B] = 1
    adjm[B][A] = 1

ans = [0]*(N+1)

from collections import deque

q = deque([1])
visited = set()
visited.add(1)
while q:
    now = q.popleft()
    for i, room in enumerate(adjm[now]):
        if room == 0: continue
        if i not in visited:
            q.append(i)
            visited.add(i)
            ans[i] = now

f = True
for i, e in enumerate(ans):
    if i == 0: continue
    if i == 1: continue
    if e == 0:
        f = False

if f:
    print("Yes")
    for i, e in enumerate(ans):
        if i == 0: continue
        if i == 1: continue
        print(e)
else:
    print("No")

Fixed submission:
from collections import deque

def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())


n, m = mapint_inp()
graph = [[] for _ in range(n)]
ans = [0]*n

for _ in range(m):
    a, b = mapint_inp()
    a -= 1; b -= 1
    graph[a].append(b)
    graph[b].append(a) 

q = deque([0])
visited = [False]*n
visited[0] = True
while q:
    now = q.popleft()
    for i in graph[now]:
        if visited[i]: continue
        visited[i] = True
        ans[i] = now
        q.append(i)

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