from collections import deque

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

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



for i in range(M):

    x, y = list(map(int, input().split()))

    G[x].append(y)

    G[y].append(x)



USED = [-1] * (N+1)

USED[0] = 0

USED[1] = 0



Q = deque()

Q.append(1)



while Q:

    x = Q.pop()

    for t in G[x]:

        if USED[t] == -1:

            Q.appendleft(t)

            USED[t] = x



if -1 in USED:

    print("No")

else:

    print("Yes")

    print((*USED[2:]))

import sys

input = sys.stdin.readline



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

E=[[] for i in range(N+1)]



for i in range(M):

    x,y=list(map(int,input().split()))

    E[x].append(y)

    E[y].append(x)



USE=[-1]*(N+1)

USE[0]=0

USE[1]=0



from collections import deque

Q=deque()

Q.append(1)

while Q:

    x=Q.pop()

    for to in E[x]:

        if USE[to]==-1:

            USE[to]=x

            Q.appendleft(to)



if -1 in USE:

    print("No")

else:

    print("Yes")

    print((*USE[2:]))
from collections import deque

N, M = list(map(int, input().split()))
G = [[] for _ in range(N + 1)]
for i in range(M):
    x, y = list(map(int, input().split()))
    G[x].append(y)
    G[y].append(x)
USED = [-1] * (N + 1)
USED[0] = 0
USED[1] = 0
Q = deque()
Q.append(1)
while Q:
    x = Q.pop()
    for t in G[x]:
        if USED[t] == -1:
            Q.appendleft(t)
            USED[t] = x
if -1 in USED:
    print("No")
else:
    print("Yes")
    print((*USED[2:]))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
E = [[] for i in range(N + 1)]
for i in range(M):
    x, y = list(map(int, input().split()))
    E[x].append(y)
    E[y].append(x)
USE = [-1] * (N + 1)
USE[0] = 0
USE[1] = 0
from collections import deque

Q = deque()
Q.append(1)
while Q:
    x = Q.pop()
    for to in E[x]:
        if USE[to] == -1:
            USE[to] = x
            Q.appendleft(to)
if -1 in USE:
    print("No")
else:
    print("Yes")
    print((*USE[2:]))

+import sys + +input = sys.stdin.readline +N, M = list(map(int, input().split())) +E = [[] for i in range(N + 1)] +for i in range(M): +    x, y = list(map(int, input().split())) +    E[x].append(y) +    E[y].append(x) +USE = [-1] * (N + 1) +USE[0] = 0 +USE[1] = 0 -N, M = list(map(int, input().split())) -G = [[] for _ in range(N + 1)] -for i in range(M): -    x, y = list(map(int, input().split())) -    G[x].append(y) -    G[y].append(x) -USED = [-1] * (N + 1) -USED[0] = 0 -USED[1] = 0 -    for t in G[x]: -        if USED[t] == -1: -            Q.appendleft(t) -            USED[t] = x -if -1 in USED: +    for to in E[x]: +        if USE[to] == -1: +            USE[to] = x +            Q.appendleft(to) +if -1 in USE: -    print((*USED[2:])) +    print((*USE[2:]))