from collections import deque



N, M = map(int, input().split())

G = [[] for i in range(N)]

for i in range(M):

    a, b = map(int, input().split())

    a -= 1

    b -= 1

    G[a].append(b)

    G[b].append(a)

q = deque()

done = [-1]*N

done[0] = 1

q.appendleft(0)

while q:

    now = q.pop()

    for to in G[now]:

        if done[to] != -1: continue

        done[to] = now+1

        q.appendleft(to)

print("Yes")

print(*done[1:], sep="\n")

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)

from collections import deque



N, M = map(int, input().split())

G = [[] for i in range(N)]

for i in range(M):

    a, b = map(int, input().split())

    a -= 1

    b -= 1

    G[a].append(b)

    G[b].append(a)

q = deque()

done = [-1]*N

done[0] = 1

q.appendleft(0)

while q:

    now = q.pop()

    for to in G[now]:

        if done[to] != -1: continue

        done[to] = now+1

        q.appendleft(to)

print("Yes")

print(*done[1:], sep="\n")

from collections import deque

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
q = deque()
done = [-1] * N
done[0] = 1
q.appendleft(0)
while q:
    now = q.pop()
    for to in G[now]:
        if done[to] != -1:
            continue
        done[to] = now + 1
        q.appendleft(to)
print("Yes")
print(*done[1:], sep="\n")

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import deque

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
q = deque()
done = [-1] * N
done[0] = 1
q.appendleft(0)
while q:
    now = q.pop()
    for to in G[now]:
        if done[to] != -1:
            continue
        done[to] = now + 1
        q.appendleft(to)
print("Yes")
print(*done[1:], sep="\n")

+import sys + +input = sys.stdin.readline +sys.setrecursionlimit(10**7)