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, prev):

    while queue:

        current = queue.popleft()



        for n in graph[current]:

            if prev[n] != -1:

                continue

            prev[n] = current

            queue.append(n)



queue = deque([1])

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

prev[1] = 0

bfs(graph, queue, prev)



if -1 not in prev:

    print('Yes')

    for i in prev[2:]:

        print(i)

else:

    print('No')

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 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



bfs(graph, queue, dist, prev)



if -1 in prev:

    print('No')

else:

    print('Yes')

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

        print((prev[i]))

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, prev):
    while queue:
        current = queue.popleft()
        for n in graph[current]:
            if prev[n] != -1:
                continue
            prev[n] = current
            queue.append(n)


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

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 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
bfs(graph, queue, dist, prev)
if -1 in prev:
    print("No")
else:
    print("Yes")
    for i in range(2, n + 1):
        print((prev[i]))

-def bfs(graph, queue, prev): +def bfs(graph, queue, dist, prev): -            if prev[n] != -1: +            if dist[n] != -1: -            prev[n] = current -            queue.append(n) +            else: +                dist[n] = dist[current] + 1 +                prev[n] = current +                queue.append(n) +dist = [0] + [-1] * n -prev[1] = 0 -bfs(graph, queue, prev) -if -1 not in prev: +bfs(graph, queue, dist, prev) +if -1 in prev: +    print("No") +else: -    for i in prev[2:]: -        print(i) -else: -    print("No") +    for i in range(2, n + 1): +        print((prev[i]))