from collections import deque

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

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

for i in range(M):

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

  ab[a].append(b)

  ab[b].append(a)

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

que=deque([1])

while que:

  q=que.popleft()

  for i in ab[q]:

    if ans[i]==-1:

      que.append(i)

      ans[i]=q

print('Yes')

for i in range(2,N+1):

  print((ans[i]))
import collections



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

g=[[] for _ in range(n+1)]

for _ in range(m):

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

  g[a].append(b)

  g[b].append(a)

q=collections.deque()

q.append(1)

check=[0]*(n+1)

check[1]=1

ans=[0]*(n+1)

while len(q)!=0:

  v=q.popleft()

  for u in g[v]:

    if check[u]==0: #まだ探索していない頂点について、その頂点に親の頂点に移動する道しるべを置く

      check[u]=1

      ans[u]=v

      q.append(u)

print('Yes')

for i in range(2,n+1):

  print((ans[i]))
from collections import deque

N, M = list(map(int, input().split()))
ab = [[] for i in range(N + 1)]
for i in range(M):
    a, b = list(map(int, input().split()))
    ab[a].append(b)
    ab[b].append(a)
ans = [-1] * (N + 1)
que = deque([1])
while que:
    q = que.popleft()
    for i in ab[q]:
        if ans[i] == -1:
            que.append(i)
            ans[i] = q
print("Yes")
for i in range(2, N + 1):
    print((ans[i]))

import collections

n, m = list(map(int, input().split()))
g = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = list(map(int, input().split()))
    g[a].append(b)
    g[b].append(a)
q = collections.deque()
q.append(1)
check = [0] * (n + 1)
check[1] = 1
ans = [0] * (n + 1)
while len(q) != 0:
    v = q.popleft()
    for u in g[v]:
        if check[u] == 0:  # まだ探索していない頂点について、その頂点に親の頂点に移動する道しるべを置く
            check[u] = 1
            ans[u] = v
            q.append(u)
print("Yes")
for i in range(2, n + 1):
    print((ans[i]))

-from collections import deque +import collections -N, M = list(map(int, input().split())) -ab = [[] for i in range(N + 1)] -for i in range(M): +n, m = list(map(int, input().split())) +g = [[] for _ in range(n + 1)] +for _ in range(m): -    ab[a].append(b) -    ab[b].append(a) -ans = [-1] * (N + 1) -que = deque([1]) -while que: -    q = que.popleft() -    for i in ab[q]: -        if ans[i] == -1: -            que.append(i) -            ans[i] = q +    g[a].append(b) +    g[b].append(a) +q = collections.deque() +q.append(1) +check = [0] * (n + 1) +check[1] = 1 +ans = [0] * (n + 1) +while len(q) != 0: +    v = q.popleft() +    for u in g[v]: +        if check[u] == 0:  # まだ探索していない頂点について、その頂点に親の頂点に移動する道しるべを置く +            check[u] = 1 +            ans[u] = v +            q.append(u) -for i in range(2, N + 1): +for i in range(2, n + 1):