import heapq



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

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

rlt = [-1]*(N+1)



for _ in range(M):

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

  nl[a].append(b)

  nl[b].append(a)



ds = [float('inf')]*(N+1)

ds[1] = 0

h = []

heapq.heappush(h,[0,1])



while(len(h) > 0):

  tmp = heapq.heappop(h)

  v = tmp[1]

  if ds[v] < tmp[0]:

    continue

  for j in nl[v]:

    if ds[j] > ds[v] + 1:

      ds[j] = ds[v] + 1

      rlt[j] = v

      heapq.heappush(h,[ds[j],j])



if -1 in rlt[2:]:

  print('No')

else:

  print('Yes')

  for i in rlt[2:]:

    print(i)
from collections import deque

 

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

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

rlt = [-1]*(N+1)

 

for _ in range(M):

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

  nl[a].append(b)

  nl[b].append(a)



ds = [float('inf')]*(N+1)

ds[1] = 0

h = deque()

h.append(1)

 

while(len(h) > 0):

  v = h.popleft()

  for j in nl[v]:

    if ds[j] == float('inf'):

      ds[j] = ds[v] + 1

      rlt[j] = v

      h.append(j)



if -1 in rlt[2:]:

  print('No')

else:

  print('Yes')

  for i in rlt[2:]:

    print(i)
import heapq

N, M = list(map(int, input().split()))
nl = {i: [] for i in range(1, N + 1)}
rlt = [-1] * (N + 1)
for _ in range(M):
    a, b = list(map(int, input().split()))
    nl[a].append(b)
    nl[b].append(a)
ds = [float("inf")] * (N + 1)
ds[1] = 0
h = []
heapq.heappush(h, [0, 1])
while len(h) > 0:
    tmp = heapq.heappop(h)
    v = tmp[1]
    if ds[v] < tmp[0]:
        continue
    for j in nl[v]:
        if ds[j] > ds[v] + 1:
            ds[j] = ds[v] + 1
            rlt[j] = v
            heapq.heappush(h, [ds[j], j])
if -1 in rlt[2:]:
    print("No")
else:
    print("Yes")
    for i in rlt[2:]:
        print(i)

from collections import deque

N, M = list(map(int, input().split()))
nl = {i: [] for i in range(1, N + 1)}
rlt = [-1] * (N + 1)
for _ in range(M):
    a, b = list(map(int, input().split()))
    nl[a].append(b)
    nl[b].append(a)
ds = [float("inf")] * (N + 1)
ds[1] = 0
h = deque()
h.append(1)
while len(h) > 0:
    v = h.popleft()
    for j in nl[v]:
        if ds[j] == float("inf"):
            ds[j] = ds[v] + 1
            rlt[j] = v
            h.append(j)
if -1 in rlt[2:]:
    print("No")
else:
    print("Yes")
    for i in rlt[2:]:
        print(i)

-import heapq +from collections import deque -h = [] -heapq.heappush(h, [0, 1]) +h = deque() +h.append(1) -    tmp = heapq.heappop(h) -    v = tmp[1] -    if ds[v] < tmp[0]: -        continue +    v = h.popleft() -        if ds[j] > ds[v] + 1: +        if ds[j] == float("inf"): -            heapq.heappush(h, [ds[j], j]) +            h.append(j)