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

n,m,*ab = map(int, open(0).read().split())
to = [[] for _ in range(m+1)]

for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

ans = [None for _ in range(n+1)]
q = deque([1])
while q:
    p = q.pop()
    for i in to[p]:
        if ans[i] is None:
            ans[i] = p
            q.appendleft(i)

print("Yes")
print("\n".join(map(str, ans[2:])))


Fixed submission:
from collections import deque
n,m,*ab = map(int, open(0).read().split())

to = [[] for _ in range(n+1)]
ans = [None] * (n+1)
for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

q = deque([1])
while q:
    p = q.pop()
    children = to[p]
    for child in children:
        if ans[child] is None:
            ans[child] = p
            q.appendleft(child)

print("Yes")
print("\n".join(map(str, ans[2:])))

Buggy python submission (verdict: Runtime Error):
n,m,*ab = map(int, open(0).read().split())
to = [[] for _ in range(m+1)]

for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

checked = set()
ans = [None for _ in range(n+1)]
def fill(k):
    if k in checked:
        return
    checked.add(k)
    for i in to[k]:
        if ans[i] is None:
            ans[i] = k
    for i in to[k]:
        fill(i)
fill(1)

print("Yes")
print("\n".join(map(str, ans[2:])))

Fixed submission:
from collections import deque
n,m,*ab = map(int, open(0).read().split())

to = [[] for _ in range(n+1)]
ans = [None] * (n+1)
for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

q = deque([1])
while q:
    p = q.pop()
    children = to[p]
    for child in children:
        if ans[child] is None:
            ans[child] = p
            q.appendleft(child)

print("Yes")
print("\n".join(map(str, ans[2:])))

Buggy python submission (verdict: Runtime Error):
from collections import deque
n,m,*ab = map(int, open(0).read().split())

to = [set() for _ in range(n+1)]
ans = [None] * (n+1)
for i in range(0, n*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].add(b)
    to[b].add(a)

q = deque([1])
while q:
    p = q.pop()
    children = to[p]
    for child in children:
        if ans[child] is None:
            ans[child] = p
            q.appendleft(child)

print("Yes")
print("\n".join(map(str, ans[2:])))

Fixed submission:
from collections import deque
n,m,*ab = map(int, open(0).read().split())

to = [[] for _ in range(n+1)]
ans = [None] * (n+1)
for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

q = deque([1])
while q:
    p = q.pop()
    children = to[p]
    for child in children:
        if ans[child] is None:
            ans[child] = p
            q.appendleft(child)

print("Yes")
print("\n".join(map(str, ans[2:])))

Buggy python submission (verdict: Runtime Error):
import math
n,m,*ab = map(int, open(0).read().split())

def calc():
    h = {}
    for i in range(0, n*2, 2):
        a = ab[i]
        b = ab[i+1]
        if a not in h:
            h[a] = set([b])
        else:
            h[a].add(b)
        if b not in h:
            h[b] = set([a])
        else:
            h[b].add(a)

    m = {}
    checked = set()
    def fill(k, d):
        if k in checked:
            return
        checked.add(k)
        if k in m:
            m[k] = min(m[k], d - 1)
        else:
            m[k] = d - 1
        for i in h[k]:
            if i in m:
                m[i] = min(m[i], d)
            else:
                m[i] = d
        for i in h[k]:
            fill(i, d+1)

    fill(1, 1)

    return [m[i] for i in range(2, n+1)]

ans = calc()
if ans is None:
    print("No")
else:
    print("Yes")
    print("\n".join(map(str, ans)))

Fixed submission:
from collections import deque
n,m,*ab = map(int, open(0).read().split())

to = [[] for _ in range(n+1)]
ans = [None] * (n+1)
for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

q = deque([1])
while q:
    p = q.pop()
    children = to[p]
    for child in children:
        if ans[child] is None:
            ans[child] = p
            q.appendleft(child)

print("Yes")
print("\n".join(map(str, ans[2:])))