from collections import deque



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

AB = [list(map(int, input().split())) for _ in range(M)]

#print(AB)

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

for a, b in AB:

    links[a].append(b)

    links[b].append(a)

#print(AB)

#print(links)

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

q = deque([1])

#print(q)

while q:

    i = q.popleft()

    for j in links[i]:

        if result[j] == -1:

            result[j] = i

            q.append(j)

            #print(q)

print('Yes')

print(('\n'.join(str(i) for i in result[2:])))
from collections import deque



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

A = [0] * M

B = [0] * M

for i in range(M):

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

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

for i in range(len(A)):

    links[A[i]].append(B[i])

    links[B[i]].append(A[i])

    

#print(links)

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

q = deque([1])

#print(q)

while q:

    i = q.popleft()

    for j in links[i]:

        if result[j] == -1:

            result[j] = i

            q.append(j)

            #print(q)

print('Yes')

print(('\n'.join(str(i) for i in result[2:])))
from collections import deque

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
# print(AB)
links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)
# print(AB)
# print(links)
result = [-1] * (N + 1)
q = deque([1])
# print(q)
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
            # print(q)
print("Yes")
print(("\n".join(str(i) for i in result[2:])))

from collections import deque

N, M = list(map(int, input().split()))
A = [0] * M
B = [0] * M
for i in range(M):
    A[i], B[i] = list(map(int, input().split()))
links = [[] for _ in range(N + 1)]
for i in range(len(A)):
    links[A[i]].append(B[i])
    links[B[i]].append(A[i])
# print(links)
result = [-1] * (N + 1)
q = deque([1])
# print(q)
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
            # print(q)
print("Yes")
print(("\n".join(str(i) for i in result[2:])))

-AB = [list(map(int, input().split())) for _ in range(M)] -# print(AB) +A = [0] * M +B = [0] * M +for i in range(M): +    A[i], B[i] = list(map(int, input().split())) -for a, b in AB: -    links[a].append(b) -    links[b].append(a) -# print(AB) +for i in range(len(A)): +    links[A[i]].append(B[i]) +    links[B[i]].append(A[i])