import queue



n,m=list(map(int,input().split()))



to = [[] for i in range(n+1)]

pre = [-1] * (n+1)

for i in range(m):

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

    to[a].append(b)

    to[b].append(a)



q = queue.Queue()

q.put((1,0))

while not q.empty():

    x,p = q.get()

    if pre[x] != -1:

        continue

    

    pre[x] = p

    for i in to[x]:

        if pre[i] == -1:

            q.put((i,x))



print('Yes')

for p in pre[2:]:

    print(p)
from collections import deque



n,m = list(map(int,input().split()))



adj = [[] for i in range(n+1)]

dist = [-1]*(n+1)



for i in range(m):

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

    adj[a].append(b)

    adj[b].append(a)



d = deque([[1,0]])



while len(d) > 0:

    x,y = d.popleft()

    if dist[x] != -1:

        continue

    

    dist[x] = y

    

    for n in adj[x]:

        if dist[n] == -1:

            d.append([n,x])



print("Yes")



for i in dist[2:]:

    print(i)
import queue

n, m = list(map(int, input().split()))
to = [[] for i in range(n + 1)]
pre = [-1] * (n + 1)
for i in range(m):
    a, b = list(map(int, input().split()))
    to[a].append(b)
    to[b].append(a)
q = queue.Queue()
q.put((1, 0))
while not q.empty():
    x, p = q.get()
    if pre[x] != -1:
        continue
    pre[x] = p
    for i in to[x]:
        if pre[i] == -1:
            q.put((i, x))
print("Yes")
for p in pre[2:]:
    print(p)

from collections import deque

n, m = list(map(int, input().split()))
adj = [[] for i in range(n + 1)]
dist = [-1] * (n + 1)
for i in range(m):
    a, b = list(map(int, input().split()))
    adj[a].append(b)
    adj[b].append(a)
d = deque([[1, 0]])
while len(d) > 0:
    x, y = d.popleft()
    if dist[x] != -1:
        continue
    dist[x] = y
    for n in adj[x]:
        if dist[n] == -1:
            d.append([n, x])
print("Yes")
for i in dist[2:]:
    print(i)

-import queue +from collections import deque -to = [[] for i in range(n + 1)] -pre = [-1] * (n + 1) +adj = [[] for i in range(n + 1)] +dist = [-1] * (n + 1) -    to[a].append(b) -    to[b].append(a) -q = queue.Queue() -q.put((1, 0)) -while not q.empty(): -    x, p = q.get() -    if pre[x] != -1: +    adj[a].append(b) +    adj[b].append(a) +d = deque([[1, 0]]) +while len(d) > 0: +    x, y = d.popleft() +    if dist[x] != -1: -    pre[x] = p -    for i in to[x]: -        if pre[i] == -1: -            q.put((i, x)) +    dist[x] = y +    for n in adj[x]: +        if dist[n] == -1: +            d.append([n, x]) -for p in pre[2:]: -    print(p) +for i in dist[2:]: +    print(i)