import queue

import sys



readline = sys.stdin.readline





def main():

    n_rooms, n_passages = list(map(int, input().split()))

    passages = (list(map(int, readline().strip().split())) for _ in range(n_passages))



    # n_rooms, n_passages, *passages = map(int, open(0).read().split())



    connections = [set() for _ in range(n_rooms+1)]  # type: list

    for a, b in passages:

        connections[a].add(b)

        connections[b].add(a)



    que = queue.Queue()

    que.put((0, 1))  # parent, current



    signs = [-1] * (n_rooms + 1)



    while not que.empty():

        parent, current = que.get()



        if signs[current] != -1:

            continue



        signs[current] = parent



        for room in connections[current]:

            if signs[room] == -1:

                que.put((current, room))



    print('Yes')

    print(('\n'.join(map(str, signs[2:]))))





if __name__ == "__main__":

    main()

# import queue

from collections import deque

import sys



readline = sys.stdin.readline





def main():

    n_rooms, n_passages = list(map(int, input().split()))

    passages = (list(map(int, readline().strip().split())) for _ in range(n_passages))



    connections = [set() for _ in range(n_rooms+1)]  # type: list

    for a, b in passages:

        connections[a].add(b)

        connections[b].add(a)



    que = deque()

    que.append((0, 1))  # parent, current



    signs = [-1] * (n_rooms + 1)



    while que:

        parent, current = que.popleft()



        if signs[current] != -1:

            continue



        signs[current] = parent



        for room in connections[current]:

            if signs[room] == -1:

                que.append((current, room))



    print('Yes')

    for sign in signs[2:]:

        print(sign)





if __name__ == "__main__":

    main()

import queue
import sys

readline = sys.stdin.readline


def main():
    n_rooms, n_passages = list(map(int, input().split()))
    passages = (list(map(int, readline().strip().split())) for _ in range(n_passages))
    # n_rooms, n_passages, *passages = map(int, open(0).read().split())
    connections = [set() for _ in range(n_rooms + 1)]  # type: list
    for a, b in passages:
        connections[a].add(b)
        connections[b].add(a)
    que = queue.Queue()
    que.put((0, 1))  # parent, current
    signs = [-1] * (n_rooms + 1)
    while not que.empty():
        parent, current = que.get()
        if signs[current] != -1:
            continue
        signs[current] = parent
        for room in connections[current]:
            if signs[room] == -1:
                que.put((current, room))
    print("Yes")
    print(("\n".join(map(str, signs[2:]))))


if __name__ == "__main__":
    main()

# import queue
from collections import deque
import sys

readline = sys.stdin.readline


def main():
    n_rooms, n_passages = list(map(int, input().split()))
    passages = (list(map(int, readline().strip().split())) for _ in range(n_passages))
    connections = [set() for _ in range(n_rooms + 1)]  # type: list
    for a, b in passages:
        connections[a].add(b)
        connections[b].add(a)
    que = deque()
    que.append((0, 1))  # parent, current
    signs = [-1] * (n_rooms + 1)
    while que:
        parent, current = que.popleft()
        if signs[current] != -1:
            continue
        signs[current] = parent
        for room in connections[current]:
            if signs[room] == -1:
                que.append((current, room))
    print("Yes")
    for sign in signs[2:]:
        print(sign)


if __name__ == "__main__":
    main()

-import queue +# import queue +from collections import deque -    # n_rooms, n_passages, *passages = map(int, open(0).read().split()) -    que = queue.Queue() -    que.put((0, 1))  # parent, current +    que = deque() +    que.append((0, 1))  # parent, current -    while not que.empty(): -        parent, current = que.get() +    while que: +        parent, current = que.popleft() -                que.put((current, room)) +                que.append((current, room)) -    print(("\n".join(map(str, signs[2:])))) +    for sign in signs[2:]: +        print(sign)