import numpy as np

import sys

sys.setrecursionlimit(10**7)

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

R = [[] for _ in range(N)]

ans = np.zeros(N,dtype=int)

ans[0] = 1

queue = [1]

for _ in range(M):

    i,j = list(map(int,input().split()))

    R[i-1].append(j)

    R[j-1].append(i)

    

def bfs(que):

    if que==[]:

        return

    i = que[0]

    for j in R[i-1]:

        if ans[j-1]==0:

            ans[j-1]=i

            que.append(j)

    que.pop(0)

    bfs(que)

    

bfs(queue)

print('Yes')

for i in range(1,N):

    print((ans[i]))
# D - .. (Double Dots)

from collections import deque



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

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

for _ in range(M):

    A,B = list(map(int,input().split()))

    route[A].append(B)

    route[B].append(A)

    

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

que = deque([1])



while len(que)>0:

    k = que.popleft()

    for x in route[k]:

        if ans[x]<0:

            ans[x] = k

            que.append(x)



print('Yes')

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

    print((ans[i]))
import numpy as np
import sys

sys.setrecursionlimit(10**7)
N, M = list(map(int, input().split()))
R = [[] for _ in range(N)]
ans = np.zeros(N, dtype=int)
ans[0] = 1
queue = [1]
for _ in range(M):
    i, j = list(map(int, input().split()))
    R[i - 1].append(j)
    R[j - 1].append(i)


def bfs(que):
    if que == []:
        return
    i = que[0]
    for j in R[i - 1]:
        if ans[j - 1] == 0:
            ans[j - 1] = i
            que.append(j)
    que.pop(0)
    bfs(que)


bfs(queue)
print("Yes")
for i in range(1, N):
    print((ans[i]))

# D - .. (Double Dots)
from collections import deque

N, M = list(map(int, input().split()))
route = [deque([]) for _ in range(N + 1)]
for _ in range(M):
    A, B = list(map(int, input().split()))
    route[A].append(B)
    route[B].append(A)
ans = [0] * 2 + [-1] * (N - 1)
que = deque([1])
while len(que) > 0:
    k = que.popleft()
    for x in route[k]:
        if ans[x] < 0:
            ans[x] = k
            que.append(x)
print("Yes")
for i in range(2, N + 1):
    print((ans[i]))

-import numpy as np -import sys +# D - .. (Double Dots) +from collections import deque -sys.setrecursionlimit(10**7) -R = [[] for _ in range(N)] -ans = np.zeros(N, dtype=int) -ans[0] = 1 -queue = [1] +route = [deque([]) for _ in range(N + 1)] -    i, j = list(map(int, input().split())) -    R[i - 1].append(j) -    R[j - 1].append(i) - - -def bfs(que): -    if que == []: -        return -    i = que[0] -    for j in R[i - 1]: -        if ans[j - 1] == 0: -            ans[j - 1] = i -            que.append(j) -    que.pop(0) -    bfs(que) - - -bfs(queue) +    A, B = list(map(int, input().split())) +    route[A].append(B) +    route[B].append(A) +ans = [0] * 2 + [-1] * (N - 1) +que = deque([1]) +while len(que) > 0: +    k = que.popleft() +    for x in route[k]: +        if ans[x] < 0: +            ans[x] = k +            que.append(x) -for i in range(1, N): +for i in range(2, N + 1):