import sys

readline = sys.stdin.buffer.readline

read = sys.stdin.buffer.read



N, M = list(map(int, readline().split()))

m = list(map(int, read().split()))

AB = list(zip(m, m))

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

for a, b in AB:

    graph[a].append(b)

    graph[b].append(a)



root = 1

q = [root]

checked = [0] * (N + 1)

checked[root] = 1

order = []

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

d = 0

while q:

    x = q.pop(0)

    d = D[x]

    for y in graph[x]:

        if checked[y]:

            continue

        D[y] = d + 1

        checked[y] = 1

        q.append(y)



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

for a, b in AB:

    d_a, d_b = D[a], D[b]

    if d_a < d_b:

        ans[b] = a

    elif d_a > d_b:

        ans[a] = b



print('Yes')

print(('\n'.join(map(str, ans[2:]))))
import sys

readline = sys.stdin.buffer.readline



N, M = list(map(int, readline().split()))

ans = [0] * (N+1)

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



for _ in range(M):

    a, b = list(map(int, readline().split()))

    graph[a].append(b)

    graph[b].append(a)



root = 1

q = [root]

checked = [0] * (N + 1)

checked[root] = 1



while q:

    x = q.pop(0)

    for y in graph[x]:

        if checked[y]:

            continue

        ans[y] = x

        checked[y] = 1

        q.append(y)



print('Yes')

print(('\n'.join(map(str, ans[2:]))))
import sys

readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N, M = list(map(int, readline().split()))
m = list(map(int, read().split()))
AB = list(zip(m, m))
graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
root = 1
q = [root]
checked = [0] * (N + 1)
checked[root] = 1
order = []
D = [0 for _ in range(N + 1)]
d = 0
while q:
    x = q.pop(0)
    d = D[x]
    for y in graph[x]:
        if checked[y]:
            continue
        D[y] = d + 1
        checked[y] = 1
        q.append(y)
ans = [0 for _ in range(N + 1)]
for a, b in AB:
    d_a, d_b = D[a], D[b]
    if d_a < d_b:
        ans[b] = a
    elif d_a > d_b:
        ans[a] = b
print("Yes")
print(("\n".join(map(str, ans[2:]))))

import sys

readline = sys.stdin.buffer.readline
N, M = list(map(int, readline().split()))
ans = [0] * (N + 1)
graph = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = list(map(int, readline().split()))
    graph[a].append(b)
    graph[b].append(a)
root = 1
q = [root]
checked = [0] * (N + 1)
checked[root] = 1
while q:
    x = q.pop(0)
    for y in graph[x]:
        if checked[y]:
            continue
        ans[y] = x
        checked[y] = 1
        q.append(y)
print("Yes")
print(("\n".join(map(str, ans[2:]))))

-read = sys.stdin.buffer.read -m = list(map(int, read().split())) -AB = list(zip(m, m)) +ans = [0] * (N + 1) -for a, b in AB: +for _ in range(M): +    a, b = list(map(int, readline().split())) -order = [] -D = [0 for _ in range(N + 1)] -d = 0 -    d = D[x] -        D[y] = d + 1 +        ans[y] = x -ans = [0 for _ in range(N + 1)] -for a, b in AB: -    d_a, d_b = D[a], D[b] -    if d_a < d_b: -        ans[b] = a -    elif d_a > d_b: -        ans[a] = b