Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n,m = map(int,input().split())
graph = defaultdict(list)
for i in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = [None]*(n-1)
check = [i for i in range(2,n+1)]
tmp = []
for j in graph[1]:
    ans[j-2] = 1
    check.remove(j)
    tmp.append(j)

count = 0
while check != [] and count < n:
    new_tmp = []
    for i in tmp:
        for j in graph[i]:
            if ans[j-2] == None and j in check:
                ans[j-2] = i
                check.remove(j)
                new_tmp.append(j)
    tmp = new_tmp
    count += 1
if None in ans:
    print('No')
else:
    print('Yes')
    for i in ans:
        print(i)

Fixed submission:
from collections import defaultdict
n,m = map(int,input().split())
graph = defaultdict(list)
for i in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = defaultdict(int)
next_list = []
for j in graph[1]:
    ans[j] = 1
    next_list.append(j)

target_list = next_list[:]
while True:
    next_list = []
    if len(target_list) == 0:
        break

    for i in target_list:
        for j in graph[i]:
            if j not in ans:
                ans[j] = i
                next_list.append(j)
    target_list = next_list[:]


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

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n,m = map(int,input().split())
graph = defaultdict(list)
for i in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = [None]*(n-1)
check = [i for i in range(2,n+1)]
tmp = []
for j in graph[1]:
    ans[j-2] = 1
    check.remove(j)
    tmp.append(j)

while check != []:
    new_tmp = []
    for i in tmp:
        for j in graph[i]:
            if ans[j-2] == None and j != 1:
                ans[j-2] = i
                check.remove(j)
                new_tmp.append(j)
    tmp = new_tmp
if None in ans:
    print('No')
else:
    print('Yes')
    for i in ans:
        print(i)

Fixed submission:
from collections import defaultdict
n,m = map(int,input().split())
graph = defaultdict(list)
for i in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = defaultdict(int)
next_list = []
for j in graph[1]:
    ans[j] = 1
    next_list.append(j)

target_list = next_list[:]
while True:
    next_list = []
    if len(target_list) == 0:
        break

    for i in target_list:
        for j in graph[i]:
            if j not in ans:
                ans[j] = i
                next_list.append(j)
    target_list = next_list[:]


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

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n,m = map(int,input().split())
graph = defaultdict(list)
for i in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = [None]*(n-1)
check = [i for i in range(2,n+1)]
tmp = []
for j in graph[1]:
    ans[j-2] = 1
    check.remove(j)
    tmp.append(j)

while check != []:
    new_tmp = []
    for i in tmp:
        for j in graph[i]:
            if ans[j-2] == None and j != 1:
                ans[j-2] = i
                check.remove(j)
                new_tmp.append(j)
    tmp = new_tmp
print(ans)

Fixed submission:
from collections import defaultdict
n,m = map(int,input().split())
graph = defaultdict(list)
for i in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = defaultdict(int)
next_list = []
for j in graph[1]:
    ans[j] = 1
    next_list.append(j)

target_list = next_list[:]
while True:
    next_list = []
    if len(target_list) == 0:
        break

    for i in target_list:
        for j in graph[i]:
            if j not in ans:
                ans[j] = i
                next_list.append(j)
    target_list = next_list[:]


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