Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]

checked = [-1 for _ in range(N)]
checked[0] = 0
d = deque([0])
while d:
    now = d.popleft()
    for i in range(M):
        if (L[i][0] - 1 == now and checked[L[i][1]-1] == -1):
            checked[L[i][1]-1] = now + 1
            d.append(L[i][1]-1)

        if (L[i][1] - 1 == now and checked[L[i][0]-1] == -1):
            checked[L[i][0]-1] = now + 1
            d.append(L[i][0]-1)


flag = False
for i in range(1, N):
    if checked[i] == -1:
        flag = True
        break

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

Fixed submission:
from collections import deque

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
link = [[] for _ in range(N)]

for i in range(M):
    link[L[i][0]-1].append(L[i][1]-1)
    link[L[i][1]-1].append(L[i][0]-1)

checked = [-1 for _ in range(N)]
checked[0] = 0
d = deque([0])
while d:
    now = d.popleft()
    for i in range(len(link[now])):
        if checked[link[now][i]] == -1:
            checked[link[now][i]] = now + 1
            d.append(link[now][i])


flag = False
for i in range(1, N):
    if checked[i] == -1:
        flag = True
        break

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]

checked = [-1 for _ in range(N)]
checked[0] = 0
d = deque([0])
while d:
    now = d.popleft()
    for i in range(M):
        if (L[i][0] - 1 == now and checked[L[i][1]-1] == -1):
            checked[L[i][1]-1] = now + 1
            d.append(L[i][1]-1)

        if (L[i][1] - 1 == now and checked[L[i][0]-1] == -1):
            checked[L[i][0]-1] = now + 1
            d.append(L[i][0]-1)


flag = False
for i in range(1, N):
    if checked[i] == -1:
        flag = True
        break

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

Fixed submission:
from collections import deque

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
link = [[] for _ in range(N)]

for i in range(M):
    link[L[i][0]-1].append(L[i][1]-1)
    link[L[i][1]-1].append(L[i][0]-1)

checked = [-1 for _ in range(N)]
checked[0] = 0
d = deque([0])
while d:
    now = d.popleft()
    for i in range(len(link[now])):
        if checked[link[now][i]] == -1:
            checked[link[now][i]] = now + 1
            d.append(link[now][i])


flag = False
for i in range(1, N):
    if checked[i] == -1:
        flag = True
        break

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]

link = [[0 for _ in range(N)] for _ in range(N)]
for i in range(M):
    link[L[i][0]-1][L[i][1]-1] = 1
    link[L[i][1]-1][L[i][0]-1] = 1

checked = [-1 for _ in range(N)]
ans = [-1 for _ in range(N)]
checked[0] = 0
d = deque([0])
while d:
    now = d.popleft()
    for i in range(N):
        if link[now][i] == 1 and checked[i] == -1:
            checked[i] = checked[now] + 1
            ans[i] = now + 1
            d.append(i)

flag = False
for i in range(1, N):
    if ans[i] == -1:
        flag = True
        break

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

Fixed submission:
from collections import deque

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
link = [[] for _ in range(N)]

for i in range(M):
    link[L[i][0]-1].append(L[i][1]-1)
    link[L[i][1]-1].append(L[i][0]-1)

checked = [-1 for _ in range(N)]
checked[0] = 0
d = deque([0])
while d:
    now = d.popleft()
    for i in range(len(link[now])):
        if checked[link[now][i]] == -1:
            checked[link[now][i]] = now + 1
            d.append(link[now][i])


flag = False
for i in range(1, N):
    if checked[i] == -1:
        flag = True
        break

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]

link = [[0 for _ in range(N)] for _ in range(N)]
for i in range(M):
    link[L[i][0]-1][L[i][1]-1] = 1
    link[L[i][1]-1][L[i][0]-1] = 1

checked = [-1 for _ in range(N)]
ans = [-1 for _ in range(N)]
checked[0] = 0
d = deque([0])
while d:
    now = d.popleft()
    for i in range(N):
        if link[now][i] == 1 and checked[i] == -1:
            checked[i] = checked[now] + 1
            ans[i] = now + 1
            d.append(i)

flag = False
for i in range(1, N):
    if ans[i] == -1:
        flag = True
        break

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

Fixed submission:
from collections import deque

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
link = [[] for _ in range(N)]

for i in range(M):
    link[L[i][0]-1].append(L[i][1]-1)
    link[L[i][1]-1].append(L[i][0]-1)

checked = [-1 for _ in range(N)]
checked[0] = 0
d = deque([0])
while d:
    now = d.popleft()
    for i in range(len(link[now])):
        if checked[link[now][i]] == -1:
            checked[link[now][i]] = now + 1
            d.append(link[now][i])


flag = False
for i in range(1, N):
    if checked[i] == -1:
        flag = True
        break

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