# Graph

import heapq

INF = 10**18



def dijkstra(start, G):

    done = [False]*(len(G))

    dist = [INF]*(len(G))

    dist[start] = 0

    fr = [0]*N

    h = []

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

    while h:

        _, cur = heapq.heappop(h)

        if done[cur]: continue

        done[cur] = True

        for to, cost in G[cur]:

            if dist[cur]+cost < dist[to]:

                dist[to] = dist[cur]+cost

                fr[to] = cur

                heapq.heappush(h, [dist[to], to])

    return fr, dist



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

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

for i in range(M):

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

    a -= 1

    b -= 1

    G[a].append((b, 1))

    G[b].append((a, 1))

ans, dis = dijkstra(0, G)

print("Yes")

for i in range(1, N):

    print((ans[i]+1))

from collections import deque



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

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

for i in range(M):

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

    a -= 1

    b -= 1

    G[a].append(b)

    G[b].append(a)

q = deque()

done = [-1]*N

def bfs(fr, now):

    done[now] = fr

    for to in G[now]:

        if done[to] != -1: continue

        q.appendleft((now, to))

q.appendleft((0, 0))

while q:

    fr, now = q.pop()

    if done[now] == -1:

        bfs(fr, now)

print("Yes")

for fr in done[1:]:

    print((fr+1))

# Graph
import heapq

INF = 10**18


def dijkstra(start, G):
    done = [False] * (len(G))
    dist = [INF] * (len(G))
    dist[start] = 0
    fr = [0] * N
    h = []
    heapq.heappush(h, [0, start])
    while h:
        _, cur = heapq.heappop(h)
        if done[cur]:
            continue
        done[cur] = True
        for to, cost in G[cur]:
            if dist[cur] + cost < dist[to]:
                dist[to] = dist[cur] + cost
                fr[to] = cur
                heapq.heappush(h, [dist[to], to])
    return fr, dist


N, M = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    G[a].append((b, 1))
    G[b].append((a, 1))
ans, dis = dijkstra(0, G)
print("Yes")
for i in range(1, N):
    print((ans[i] + 1))

from collections import deque

N, M = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
q = deque()
done = [-1] * N


def bfs(fr, now):
    done[now] = fr
    for to in G[now]:
        if done[to] != -1:
            continue
        q.appendleft((now, to))


q.appendleft((0, 0))
while q:
    fr, now = q.pop()
    if done[now] == -1:
        bfs(fr, now)
print("Yes")
for fr in done[1:]:
    print((fr + 1))

-# Graph -import heapq - -INF = 10**18 - - -def dijkstra(start, G): -    done = [False] * (len(G)) -    dist = [INF] * (len(G)) -    dist[start] = 0 -    fr = [0] * N -    h = [] -    heapq.heappush(h, [0, start]) -    while h: -        _, cur = heapq.heappop(h) -        if done[cur]: -            continue -        done[cur] = True -        for to, cost in G[cur]: -            if dist[cur] + cost < dist[to]: -                dist[to] = dist[cur] + cost -                fr[to] = cur -                heapq.heappush(h, [dist[to], to]) -    return fr, dist - +from collections import deque -    G[a].append((b, 1)) -    G[b].append((a, 1)) -ans, dis = dijkstra(0, G) +    G[a].append(b) +    G[b].append(a) +q = deque() +done = [-1] * N + + +def bfs(fr, now): +    done[now] = fr +    for to in G[now]: +        if done[to] != -1: +            continue +        q.appendleft((now, to)) + + +q.appendleft((0, 0)) +while q: +    fr, now = q.pop() +    if done[now] == -1: +        bfs(fr, now) -for i in range(1, N): -    print((ans[i] + 1)) +for fr in done[1:]: +    print((fr + 1))