from collections import deque

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

# ab =[list(map(int,input().split())) for i in range(m)]



v = [[i,-1] for i in range(n+1)]

v[1][1] = 0

for i in range(m):

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

    v[a].append(b)

    v[b].append(a)

dq = deque([])

dq.append(v[1])

# print(v)

while dq:

    t = list(deque.popleft(dq))

    # print(t)

    for i in t[1:]:

        if v[i][1] == -1:

            v[i][1] = t[0]

            dq.append(v[i])

print("Yes")

for i in range(n-1):

    print((v[i+2][1]))
from collections import deque

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

# ab = [list(map(int,input().split())) for i in range(m)]

v = [[0]]*2 + [[10**9] for i in range(n-1)]

# print(v)

for i in range(m):

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

    v[a].append(b)

    v[b].append(a)

q = deque([1])

# print(v)

while q:

    temp = q.popleft()

    for i in v[temp][1:]:

        if v[i][0] == 10**9:

            v[i][0] = temp

            q.append(i)

print("Yes")

for i in v[2:]:

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

(
    n,
    m,
) = list(map(int, input().split()))
# ab =[list(map(int,input().split())) for i in range(m)]
v = [[i, -1] for i in range(n + 1)]
v[1][1] = 0
for i in range(m):
    a, b = list(map(int, input().split()))
    v[a].append(b)
    v[b].append(a)
dq = deque([])
dq.append(v[1])
# print(v)
while dq:
    t = list(deque.popleft(dq))
    # print(t)
    for i in t[1:]:
        if v[i][1] == -1:
            v[i][1] = t[0]
            dq.append(v[i])
print("Yes")
for i in range(n - 1):
    print((v[i + 2][1]))

from collections import deque

n, m = list(map(int, input().split()))
# ab = [list(map(int,input().split())) for i in range(m)]
v = [[0]] * 2 + [[10**9] for i in range(n - 1)]
# print(v)
for i in range(m):
    a, b = list(map(int, input().split()))
    v[a].append(b)
    v[b].append(a)
q = deque([1])
# print(v)
while q:
    temp = q.popleft()
    for i in v[temp][1:]:
        if v[i][0] == 10**9:
            v[i][0] = temp
            q.append(i)
print("Yes")
for i in v[2:]:
    print((i[0]))

-( -    n, -    m, -) = list(map(int, input().split())) -# ab =[list(map(int,input().split())) for i in range(m)] -v = [[i, -1] for i in range(n + 1)] -v[1][1] = 0 +n, m = list(map(int, input().split())) +# ab = [list(map(int,input().split())) for i in range(m)] +v = [[0]] * 2 + [[10**9] for i in range(n - 1)] +# print(v) -dq = deque([]) -dq.append(v[1]) +q = deque([1]) -while dq: -    t = list(deque.popleft(dq)) -    # print(t) -    for i in t[1:]: -        if v[i][1] == -1: -            v[i][1] = t[0] -            dq.append(v[i]) +while q: +    temp = q.popleft() +    for i in v[temp][1:]: +        if v[i][0] == 10**9: +            v[i][0] = temp +            q.append(i) -for i in range(n - 1): -    print((v[i + 2][1])) +for i in v[2:]: +    print((i[0]))