import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



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

graph = [0] + [[] for _ in range(n)]

for _ in range(m):

    n1, n2 = list(map(int, input().split()))

    graph[n1].append(n2)

    graph[n2].append(n1)



from collections import deque



def bfs(graph, queue, dist, prev):

    while queue:

        current = queue.popleft()



        for n in graph[current]:

            if dist[n] != -1:

                continue

            else:

                dist[n] = dist[current] + 1

                prev[n] = current

                queue.append(n)



queue = deque([1])

dist = [0] + [-1] * n

prev = [0] + [-1] * n

dist[1] = 0

prev[1] = 0

bfs(graph, queue, dist, prev)

if -1 in prev:

    print('No')

else:

    print('Yes')

    for n in prev[2:]:

        print(n)

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



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

graph = [0] + [[] for _ in range(n)]

for _ in range(m):

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

    graph[a].append(b)

    graph[b].append(a)



from collections import deque



def bfs(graph, queue, dist, prev):

    while queue:

        current = queue.popleft()



        for _next in graph[current]:

            if dist[_next] != -1:

                continue

            else:

                dist[_next] = dist[current] + 1

                prev[_next] = current

                queue.append(_next)



queue = deque([1])

dist = [0] + [-1] * n

prev = [0] + [-1] * n

dist[1] = 0

bfs(graph, queue, dist, prev)



if -1 in dist:

    print('No')

else:

    print('Yes')

    for v in prev[2:]:

        print(v)

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m = list(map(int, input().split()))
graph = [0] + [[] for _ in range(n)]
for _ in range(m):
    n1, n2 = list(map(int, input().split()))
    graph[n1].append(n2)
    graph[n2].append(n1)
from collections import deque


def bfs(graph, queue, dist, prev):
    while queue:
        current = queue.popleft()
        for n in graph[current]:
            if dist[n] != -1:
                continue
            else:
                dist[n] = dist[current] + 1
                prev[n] = current
                queue.append(n)


queue = deque([1])
dist = [0] + [-1] * n
prev = [0] + [-1] * n
dist[1] = 0
prev[1] = 0
bfs(graph, queue, dist, prev)
if -1 in prev:
    print("No")
else:
    print("Yes")
    for n in prev[2:]:
        print(n)

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m = list(map(int, input().split()))
graph = [0] + [[] for _ in range(n)]
for _ in range(m):
    a, b = list(map(int, input().split()))
    graph[a].append(b)
    graph[b].append(a)
from collections import deque


def bfs(graph, queue, dist, prev):
    while queue:
        current = queue.popleft()
        for _next in graph[current]:
            if dist[_next] != -1:
                continue
            else:
                dist[_next] = dist[current] + 1
                prev[_next] = current
                queue.append(_next)


queue = deque([1])
dist = [0] + [-1] * n
prev = [0] + [-1] * n
dist[1] = 0
bfs(graph, queue, dist, prev)
if -1 in dist:
    print("No")
else:
    print("Yes")
    for v in prev[2:]:
        print(v)

-    n1, n2 = list(map(int, input().split())) -    graph[n1].append(n2) -    graph[n2].append(n1) +    a, b = list(map(int, input().split())) +    graph[a].append(b) +    graph[b].append(a) -        for n in graph[current]: -            if dist[n] != -1: +        for _next in graph[current]: +            if dist[_next] != -1: -                dist[n] = dist[current] + 1 -                prev[n] = current -                queue.append(n) +                dist[_next] = dist[current] + 1 +                prev[_next] = current +                queue.append(_next) -prev[1] = 0 -if -1 in prev: +if -1 in dist: -    for n in prev[2:]: -        print(n) +    for v in prev[2:]: +        print(v)