Buggy python submission (verdict: Time Limit Exceeded):
#!python3

import sys
from collections import defaultdict

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M = iim()
    it = map(int, sys.stdin.read().split())

    d1 = defaultdict(list)

    for i, j in zip(it, it):
        d1[i].append(j)
        d1[j].append(i)

    ans = [0] * (N+1)
    dq = [1]
    visited = set([1])

    while True:
        dq2 = []
        for i in dq:
            for j in d1[i]:
                if j in visited:
                    continue
                dq2.append(j)
                ans[j] = i
            visited.update(dq2)

        if len(visited) == N:
            break
        elif not dq2:
            break

        dq = dq2

    if len(visited) == N:
        print("Yes", *ans[2:], sep="\n")
    else:
        print("No")





if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

import sys
from collections import defaultdict

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M = iim()
    it = map(int, sys.stdin.read().split())

    d1 = defaultdict(list)

    for i, j in zip(it, it):
        d1[i].append(j)
        d1[j].append(i)

    ans = [0] * (N+1)
    dq = [1]
    visited = set([1])

    updated = True
    while updated:
        updated = False
        dq2 = []
        for i in dq:
            for j in d1[i]:
                if j in visited:
                    continue
                ans[j] = i
                dq2.append(j)
                visited.add(j)
                updated = True
        dq = dq2

    if len(visited) == N:
        print("Yes", *ans[2:], sep="\n")
    else:
        print("No")






if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Runtime Error):
#!python3

import sys
from collections import defaultdict

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M = iim()
    it = map(int, sys.stdin.read().split())

    d1 = defaultdict(list)

    for i, j in zip(it, it):
        d1[i].append(j)
        d1[j].append(i)

    ans = [0] * (N+1)
    dq = [1]
    visited = set([1])
    cnt = 0

    while True:
        dq2 = []
        for i in dq:
            for j in d1[i]:
                if j in visited:
                    continue
                dq2.append(j)
                ans[j] = i
            visited.update(dq2)
            cnt += 1

        if not dq2:
            break

        dq = dq2

    if cnt == N:
        print("Yes", *ans[2:], sep="\n")
    else:
        printi("No")





if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

import sys
from collections import defaultdict

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M = iim()
    it = map(int, sys.stdin.read().split())

    d1 = defaultdict(list)

    for i, j in zip(it, it):
        d1[i].append(j)
        d1[j].append(i)

    ans = [0] * (N+1)
    dq = [1]
    visited = set([1])

    updated = True
    while updated:
        updated = False
        dq2 = []
        for i in dq:
            for j in d1[i]:
                if j in visited:
                    continue
                ans[j] = i
                dq2.append(j)
                visited.add(j)
                updated = True
        dq = dq2

    if len(visited) == N:
        print("Yes", *ans[2:], sep="\n")
    else:
        print("No")






if __name__ == "__main__":
    resolve()