from collections import deque



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

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

for i in range(M):

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

    a -= 1

    b -= 1

    G[a].append(b)

    G[b].append(a)

q = deque()

done = [-1]*N

def bfs(fr, now):

    done[now] = fr

    for to in G[now]:

        if done[to] != -1: continue

        q.appendleft((now, to))

q.appendleft((0, 0))

while q:

    fr, now = q.pop()

    if done[now] == -1:

        bfs(fr, now)

print("Yes")

for fr in done[1:]:

    print((fr+1))

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 = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
q = deque()
done = [-1] * N


def bfs(fr, now):
    done[now] = fr
    for to in G[now]:
        if done[to] != -1:
            continue
        q.appendleft((now, to))


q.appendleft((0, 0))
while q:
    fr, now = q.pop()
    if done[now] == -1:
        bfs(fr, now)
print("Yes")
for fr in done[1:]:
    print((fr + 1))

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")

-N, M = list(map(int, input().split())) +N, M = map(int, input().split()) -    a, b = list(map(int, input().split())) +    a, b = map(int, input().split()) - - -def bfs(fr, now): -    done[now] = fr +done[0] = 1 +q.appendleft(0) +while q: +    now = q.pop() -        q.appendleft((now, to)) - - -q.appendleft((0, 0)) -while q: -    fr, now = q.pop() -    if done[now] == -1: -        bfs(fr, now) +        done[to] = now + 1 +        q.appendleft(to) -for fr in done[1:]: -    print((fr + 1)) +print(*done[1:], sep="\n")