

from collections import deque

import sys

input = sys.stdin.readline

N,M = (int(x) for x in input().split())

connection ={i:set() for i in range(1,N+1)}



#構造入力

for i in range(1,M+1):

    a,b = (int(x) for x in input().split())

    connection[a].add(b)

    connection[b].add(a)



#幅優先探索

dq =deque()

dq.append(1)

parent ={i:-1 for i in range(1,N+1)} #1につながっている＝答え

parent[1] =0

while dq:

    now =dq.popleft()

    for next in connection[now]:

        if parent[next] !=-1:

            continue

        else:

            parent[next] =now

            dq.append(next)

if -1 not in parent.values():

    del parent[1]

    print("Yes")

    print(*parent.values(),sep="\n")

from collections import deque

from copy import copy

import sys

input = sys.stdin.readline

N,M = (int(x) for x in input().split())

connection ={i:[] for i in range(0,N+1)}

connection[0] =[1]

#connection[1] =[0]

#構造入力

for i in range(M):

    a,b = (int(x) for x in input().split())

    connection[a].append(b)

    connection[b].append(a)



# 幅優先探索

parent ={i:-1 for i in range(1,N+1)} #親＝通過済、通過してない部屋はー１

parent[1] =0

children = deque()

children.extend(connection[1])

for i in children:

    parent[i] =1

while children:

    next =children.popleft()



    for i in connection[next]:

        if parent[i] != -1:

            continue

        else:

            parent[i] =next



            children.append(i)

#出力

print("Yes")

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

    print((parent[i]))
from collections import deque
import sys

input = sys.stdin.readline
N, M = (int(x) for x in input().split())
connection = {i: set() for i in range(1, N + 1)}
# 構造入力
for i in range(1, M + 1):
    a, b = (int(x) for x in input().split())
    connection[a].add(b)
    connection[b].add(a)
# 幅優先探索
dq = deque()
dq.append(1)
parent = {i: -1 for i in range(1, N + 1)}  # 1につながっている＝答え
parent[1] = 0
while dq:
    now = dq.popleft()
    for next in connection[now]:
        if parent[next] != -1:
            continue
        else:
            parent[next] = now
            dq.append(next)
if -1 not in parent.values():
    del parent[1]
    print("Yes")
    print(*parent.values(), sep="\n")

from collections import deque
from copy import copy
import sys

input = sys.stdin.readline
N, M = (int(x) for x in input().split())
connection = {i: [] for i in range(0, N + 1)}
connection[0] = [1]
# connection[1] =[0]
# 構造入力
for i in range(M):
    a, b = (int(x) for x in input().split())
    connection[a].append(b)
    connection[b].append(a)
# 幅優先探索
parent = {i: -1 for i in range(1, N + 1)}  # 親＝通過済、通過してない部屋はー１
parent[1] = 0
children = deque()
children.extend(connection[1])
for i in children:
    parent[i] = 1
while children:
    next = children.popleft()
    for i in connection[next]:
        if parent[i] != -1:
            continue
        else:
            parent[i] = next
            children.append(i)
# 出力
print("Yes")
for i in range(2, N + 1):
    print((parent[i]))

+from copy import copy -connection = {i: set() for i in range(1, N + 1)} +connection = {i: [] for i in range(0, N + 1)} +connection[0] = [1] +# connection[1] =[0] -for i in range(1, M + 1): +for i in range(M): -    connection[a].add(b) -    connection[b].add(a) +    connection[a].append(b) +    connection[b].append(a) -dq = deque() -dq.append(1) -parent = {i: -1 for i in range(1, N + 1)}  # 1につながっている＝答え +parent = {i: -1 for i in range(1, N + 1)}  # 親＝通過済、通過してない部屋はー１ -while dq: -    now = dq.popleft() -    for next in connection[now]: -        if parent[next] != -1: +children = deque() +children.extend(connection[1]) +for i in children: +    parent[i] = 1 +while children: +    next = children.popleft() +    for i in connection[next]: +        if parent[i] != -1: -            parent[next] = now -            dq.append(next) -if -1 not in parent.values(): -    del parent[1] -    print("Yes") -    print(*parent.values(), sep="\n") +            parent[i] = next +            children.append(i) +# 出力 +print("Yes") +for i in range(2, N + 1): +    print((parent[i]))