from heapq import heappush, heappop, heapify

import sys

input = lambda: sys.stdin.readline().rstrip()

from collections import defaultdict



n, m = list(map(int, input().split()))

edges = defaultdict(lambda: defaultdict(lambda: float("inf")))

for _ in range(m):

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

    edges[a-1][b-1] = 1

    edges[b-1][a-1] = 1



def dijkstra(s, n, cost):

    d = [float("inf")] * n

    d[s] = 0

    que = [[0, s]]

    prev = {}

    heapify(que)

    while len(que) > 0:

        u_dist, u = heappop(que)

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

        for v in list(edges[u].keys()):

            alt = d[u] + cost[u][v]

            if d[v] > alt:

                prev[v] = u

                d[v] = alt

                heappush(que, [alt, v])

    return d, prev



_, prev = dijkstra(0, n, edges)

ans = []

ans.append("Yes")

for i in range(1, n):

    ans.append(str(prev[i]+1))

print(("\n".join(ans)))
from collections import deque



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

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

for i in range(M):

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

    a, b = a-1, b-1

    graph[a].append(b)

    graph[b].append(a)

    

dist = [-1] * N

dist[0] = 0

    

queue = deque([0])



while queue:

    v = queue.popleft()

    for nv in graph[v]:

        if (dist[nv] != -1):

            continue

        dist[nv] = v

        queue.append(nv)



print("Yes")

for i in dist[1:]:

    print((i+1))

from heapq import heappush, heappop, heapify
import sys

input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict

n, m = list(map(int, input().split()))
edges = defaultdict(lambda: defaultdict(lambda: float("inf")))
for _ in range(m):
    a, b = list(map(int, input().split()))
    edges[a - 1][b - 1] = 1
    edges[b - 1][a - 1] = 1


def dijkstra(s, n, cost):
    d = [float("inf")] * n
    d[s] = 0
    que = [[0, s]]
    prev = {}
    heapify(que)
    while len(que) > 0:
        u_dist, u = heappop(que)
        # まだ使われてない頂点の中から最小の距離のものを探す
        for v in list(edges[u].keys()):
            alt = d[u] + cost[u][v]
            if d[v] > alt:
                prev[v] = u
                d[v] = alt
                heappush(que, [alt, v])
    return d, prev


_, prev = dijkstra(0, n, edges)
ans = []
ans.append("Yes")
for i in range(1, n):
    ans.append(str(prev[i] + 1))
print(("\n".join(ans)))

from collections import deque

N, M = list(map(int, input().split()))
graph = [[] for i in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    graph[a].append(b)
    graph[b].append(a)
dist = [-1] * N
dist[0] = 0
queue = deque([0])
while queue:
    v = queue.popleft()
    for nv in graph[v]:
        if dist[nv] != -1:
            continue
        dist[nv] = v
        queue.append(nv)
print("Yes")
for i in dist[1:]:
    print((i + 1))

-from heapq import heappush, heappop, heapify -import sys +from collections import deque -input = lambda: sys.stdin.readline().rstrip() -from collections import defaultdict - -n, m = list(map(int, input().split())) -edges = defaultdict(lambda: defaultdict(lambda: float("inf"))) -for _ in range(m): +N, M = list(map(int, input().split())) +graph = [[] for i in range(N)] +for i in range(M): -    edges[a - 1][b - 1] = 1 -    edges[b - 1][a - 1] = 1 - - -def dijkstra(s, n, cost): -    d = [float("inf")] * n -    d[s] = 0 -    que = [[0, s]] -    prev = {} -    heapify(que) -    while len(que) > 0: -        u_dist, u = heappop(que) -        # まだ使われてない頂点の中から最小の距離のものを探す -        for v in list(edges[u].keys()): -            alt = d[u] + cost[u][v] -            if d[v] > alt: -                prev[v] = u -                d[v] = alt -                heappush(que, [alt, v]) -    return d, prev - - -_, prev = dijkstra(0, n, edges) -ans = [] -ans.append("Yes") -for i in range(1, n): -    ans.append(str(prev[i] + 1)) -print(("\n".join(ans))) +    a, b = a - 1, b - 1 +    graph[a].append(b) +    graph[b].append(a) +dist = [-1] * N +dist[0] = 0 +queue = deque([0]) +while queue: +    v = queue.popleft() +    for nv in graph[v]: +        if dist[nv] != -1: +            continue +        dist[nv] = v +        queue.append(nv) +print("Yes") +for i in dist[1:]: +    print((i + 1))