import sys

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

read = sys.stdin.buffer.read

sys.setrecursionlimit(10 ** 7)

INF = float('inf')



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

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



for _ in range(M):

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

    # print(A, B)

    graph[A-1].append(B-1)

    graph[B-1].append(A-1)



from collections import deque

def bfs(start):

    dist = [INF] * N

    dist[start] = 0

    seen = [0] * N

    shirube = [None] * N

    shirube[0] = 'Yes'

    q = deque([start])

    while q:

        v = q.popleft()

        dv = dist[v]

        for next_room in graph[v]:

            if seen[next_room]:

                continue

            if dv + 1 < dist[next_room]:

                dist[next_room] = dv + 1

                shirube[next_room] = v + 1

            seen[next_room] = 1

            q.append(next_room)

    if all(shirube):

        for x in shirube:

            print(x)

    else:

        # print(shirube)

        print('No')

bfs(0)
import sys

from collections import deque



readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

read = sys.stdin.buffer.read

sys.setrecursionlimit(10 ** 7)

INF = float('inf')



N, M = map(int, readline().split())



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

m = map(int, read().split())

for a, b in zip(m, m):

    G[a].append(b)

    G[b].append(a)



parents = [0] * (N+1)

visited = [0] * (N+1)

root = 1

visited[root] = 1

q = deque([root])

while q:

    v = q.popleft()

    for w in G[v]:

        if visited[w]:

            continue

        visited[w] = 1

        parents[w] = v

        q.append(w)



print('Yes')

print(*parents[2:], sep='\n')

import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10**7)
INF = float("inf")
N, M = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for _ in range(M):
    A, B = list(map(int, input().split()))
    # print(A, B)
    graph[A - 1].append(B - 1)
    graph[B - 1].append(A - 1)
from collections import deque


def bfs(start):
    dist = [INF] * N
    dist[start] = 0
    seen = [0] * N
    shirube = [None] * N
    shirube[0] = "Yes"
    q = deque([start])
    while q:
        v = q.popleft()
        dv = dist[v]
        for next_room in graph[v]:
            if seen[next_room]:
                continue
            if dv + 1 < dist[next_room]:
                dist[next_room] = dv + 1
                shirube[next_room] = v + 1
            seen[next_room] = 1
            q.append(next_room)
    if all(shirube):
        for x in shirube:
            print(x)
    else:
        # print(shirube)
        print("No")


bfs(0)

import sys
from collections import deque

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10**7)
INF = float("inf")
N, M = map(int, readline().split())
G = [[] for _ in range(N + 1)]
m = map(int, read().split())
for a, b in zip(m, m):
    G[a].append(b)
    G[b].append(a)
parents = [0] * (N + 1)
visited = [0] * (N + 1)
root = 1
visited[root] = 1
q = deque([root])
while q:
    v = q.popleft()
    for w in G[v]:
        if visited[w]:
            continue
        visited[w] = 1
        parents[w] = v
        q.append(w)
print("Yes")
print(*parents[2:], sep="\n")

+from collections import deque -N, M = list(map(int, input().split())) -graph = [[] for _ in range(N)] -for _ in range(M): -    A, B = list(map(int, input().split())) -    # print(A, B) -    graph[A - 1].append(B - 1) -    graph[B - 1].append(A - 1) -from collections import deque - - -def bfs(start): -    dist = [INF] * N -    dist[start] = 0 -    seen = [0] * N -    shirube = [None] * N -    shirube[0] = "Yes" -    q = deque([start]) -    while q: -        v = q.popleft() -        dv = dist[v] -        for next_room in graph[v]: -            if seen[next_room]: -                continue -            if dv + 1 < dist[next_room]: -                dist[next_room] = dv + 1 -                shirube[next_room] = v + 1 -            seen[next_room] = 1 -            q.append(next_room) -    if all(shirube): -        for x in shirube: -            print(x) -    else: -        # print(shirube) -        print("No") - - -bfs(0) +N, M = map(int, readline().split()) +G = [[] for _ in range(N + 1)] +m = map(int, read().split()) +for a, b in zip(m, m): +    G[a].append(b) +    G[b].append(a) +parents = [0] * (N + 1) +visited = [0] * (N + 1) +root = 1 +visited[root] = 1 +q = deque([root]) +while q: +    v = q.popleft() +    for w in G[v]: +        if visited[w]: +            continue +        visited[w] = 1 +        parents[w] = v +        q.append(w) +print("Yes") +print(*parents[2:], sep="\n")