from collections import deque





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

to = [[] for _ in range(N)]



for i in range(M):

    A, B = list(map(int, input().split()))

    to[A-1].append(B-1)

    to[B-1].append(A-1)



route = deque([0])

dist = [0]*N

prev = [-1]*N



while route:

    v = route.popleft()

    for u in to[v]:

        if dist[u]: continue

        dist[u] = dist[v]+1

        prev[u] = v

        route.append(u)



print("Yes")

for pre in prev[1:]:

    print((pre+1))
from collections import deque





def solve():

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

    to = [[] for _ in range(N)]



    for _ in range(M):

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

        a, b = a - 1, b - 1

        to[a].append(b)

        to[b].append(a)



    que = deque()

    hint = [0] * N

    seen = [False] * N



    seen[0] = True

    que.appendleft(0)



    # BFS

    while que:

        v = que.popleft()

        for nv in to[v]:

            if seen[nv]:

                continue

            que.append(nv)

            hint[nv] = v + 1

            seen[nv] = True



    print("Yes")

    print(*hint[1:], sep='\n')

    



if __name__ == "__main__":

    solve()

from collections import deque

N, M = list(map(int, input().split()))
to = [[] for _ in range(N)]
for i in range(M):
    A, B = list(map(int, input().split()))
    to[A - 1].append(B - 1)
    to[B - 1].append(A - 1)
route = deque([0])
dist = [0] * N
prev = [-1] * N
while route:
    v = route.popleft()
    for u in to[v]:
        if dist[u]:
            continue
        dist[u] = dist[v] + 1
        prev[u] = v
        route.append(u)
print("Yes")
for pre in prev[1:]:
    print((pre + 1))

from collections import deque


def solve():
    N, M = map(int, input().split())
    to = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        to[a].append(b)
        to[b].append(a)
    que = deque()
    hint = [0] * N
    seen = [False] * N
    seen[0] = True
    que.appendleft(0)
    # BFS
    while que:
        v = que.popleft()
        for nv in to[v]:
            if seen[nv]:
                continue
            que.append(nv)
            hint[nv] = v + 1
            seen[nv] = True
    print("Yes")
    print(*hint[1:], sep="\n")


if __name__ == "__main__":
    solve()

-N, M = list(map(int, input().split())) -to = [[] for _ in range(N)] -for i in range(M): -    A, B = list(map(int, input().split())) -    to[A - 1].append(B - 1) -    to[B - 1].append(A - 1) -route = deque([0]) -dist = [0] * N -prev = [-1] * N -while route: -    v = route.popleft() -    for u in to[v]: -        if dist[u]: -            continue -        dist[u] = dist[v] + 1 -        prev[u] = v -        route.append(u) -print("Yes") -for pre in prev[1:]: -    print((pre + 1)) + +def solve(): +    N, M = map(int, input().split()) +    to = [[] for _ in range(N)] +    for _ in range(M): +        a, b = map(int, input().split()) +        a, b = a - 1, b - 1 +        to[a].append(b) +        to[b].append(a) +    que = deque() +    hint = [0] * N +    seen = [False] * N +    seen[0] = True +    que.appendleft(0) +    # BFS +    while que: +        v = que.popleft() +        for nv in to[v]: +            if seen[nv]: +                continue +            que.append(nv) +            hint[nv] = v + 1 +            seen[nv] = True +    print("Yes") +    print(*hint[1:], sep="\n") + + +if __name__ == "__main__": +    solve()