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



import heapq

def dijkstra_heap(s):

  #始点sから各頂点への最短距離

  dist=[float("inf")]*size_v

  used=[False]*size_v

  dist[s]=0

  used[s]=True



  hq_edge=[]

  for v,w,i in graph[s]:

    heapq.heappush(hq_edge,(w,v,i))



  while hq_edge:

    min_w,min_v,i=heapq.heappop(hq_edge)

    #まだ使われてない頂点の中から最小の距離のものを探す

    if used[min_v]:

      continue



    dist[min_v]=min_w

    used[min_v]=True

    prev[min_v]=i

    for v,w,i2 in graph[min_v]:

      if not used[v]:

        heapq.heappush(hq_edge,(min_w+w,v,i2))



  return dist



ablist=[]

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

for i in range(M):

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

  graph[a].append((b,1,i))

  graph[b].append((a,1,i))

  ablist.append((a,b))

#print(graph)



size_v=N+1

prev=[None]*size_v

dist=dijkstra_heap(1)

#print(dist)

#print(prev)



print("Yes")

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

  prev_e=ablist[prev[i]]

  if i==prev_e[0]:

    print((prev_e[1]))

  else:

    print((prev_e[0]))

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



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

for i in range(M):

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

  graph[a].append(b)

  graph[b].append(a)

#print(graph)



queue=[1]

d=0

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

while queue:

  new_queue=set()

  for q in queue:

    if dist[q]!=-1:

      continue      

    dist[q]=d

    for v in graph[q]:

      if dist[v]==-1:

        new_queue.add(v)

        

  queue=list(new_queue)

  d+=1

#print(dist)



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

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

  for v in graph[i]:

    if dist[v]==dist[i]+1:

      parent[v]=i

#print(parent)



print("Yes")

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

  print((parent[i]))
N, M = list(map(int, input().split()))
import heapq


def dijkstra_heap(s):
    # 始点sから各頂点への最短距離
    dist = [float("inf")] * size_v
    used = [False] * size_v
    dist[s] = 0
    used[s] = True
    hq_edge = []
    for v, w, i in graph[s]:
        heapq.heappush(hq_edge, (w, v, i))
    while hq_edge:
        min_w, min_v, i = heapq.heappop(hq_edge)
        # まだ使われてない頂点の中から最小の距離のものを探す
        if used[min_v]:
            continue
        dist[min_v] = min_w
        used[min_v] = True
        prev[min_v] = i
        for v, w, i2 in graph[min_v]:
            if not used[v]:
                heapq.heappush(hq_edge, (min_w + w, v, i2))
    return dist


ablist = []
graph = [[] for _ in range(N + 1)]
for i in range(M):
    a, b = list(map(int, input().split()))
    graph[a].append((b, 1, i))
    graph[b].append((a, 1, i))
    ablist.append((a, b))
# print(graph)
size_v = N + 1
prev = [None] * size_v
dist = dijkstra_heap(1)
# print(dist)
# print(prev)
print("Yes")
for i in range(2, N + 1):
    prev_e = ablist[prev[i]]
    if i == prev_e[0]:
        print((prev_e[1]))
    else:
        print((prev_e[0]))

N, M = list(map(int, input().split()))
graph = [[] for _ in range(N + 1)]
for i in range(M):
    a, b = list(map(int, input().split()))
    graph[a].append(b)
    graph[b].append(a)
# print(graph)
queue = [1]
d = 0
dist = [-1] * (N + 1)
while queue:
    new_queue = set()
    for q in queue:
        if dist[q] != -1:
            continue
        dist[q] = d
        for v in graph[q]:
            if dist[v] == -1:
                new_queue.add(v)
    queue = list(new_queue)
    d += 1
# print(dist)
parent = [-1] * (N + 1)
for i in range(1, N + 1):
    for v in graph[i]:
        if dist[v] == dist[i] + 1:
            parent[v] = i
# print(parent)
print("Yes")
for i in range(2, N + 1):
    print((parent[i]))

-import heapq - - -def dijkstra_heap(s): -    # 始点sから各頂点への最短距離 -    dist = [float("inf")] * size_v -    used = [False] * size_v -    dist[s] = 0 -    used[s] = True -    hq_edge = [] -    for v, w, i in graph[s]: -        heapq.heappush(hq_edge, (w, v, i)) -    while hq_edge: -        min_w, min_v, i = heapq.heappop(hq_edge) -        # まだ使われてない頂点の中から最小の距離のものを探す -        if used[min_v]: -            continue -        dist[min_v] = min_w -        used[min_v] = True -        prev[min_v] = i -        for v, w, i2 in graph[min_v]: -            if not used[v]: -                heapq.heappush(hq_edge, (min_w + w, v, i2)) -    return dist - - -ablist = [] -    graph[a].append((b, 1, i)) -    graph[b].append((a, 1, i)) -    ablist.append((a, b)) +    graph[a].append(b) +    graph[b].append(a) -size_v = N + 1 -prev = [None] * size_v -dist = dijkstra_heap(1) +queue = [1] +d = 0 +dist = [-1] * (N + 1) +while queue: +    new_queue = set() +    for q in queue: +        if dist[q] != -1: +            continue +        dist[q] = d +        for v in graph[q]: +            if dist[v] == -1: +                new_queue.add(v) +    queue = list(new_queue) +    d += 1 -# print(prev) +parent = [-1] * (N + 1) +for i in range(1, N + 1): +    for v in graph[i]: +        if dist[v] == dist[i] + 1: +            parent[v] = i +# print(parent) -    prev_e = ablist[prev[i]] -    if i == prev_e[0]: -        print((prev_e[1])) -    else: -        print((prev_e[0])) +    print((parent[i]))