# import sys

# readline = sys.stdin.readline

# generator = (readline().strip() for _ in range(N))



# import numpy as np

# from itertools import permutations

# from itertools import combinations

# from itertools import combinations_with_replacement

import queue

# import heapq



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

# As = list(map(int, input().split()))

# queries = (input() for _ in range(N))





def solve():

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

    queries = (list(map(int, input().split())) for _ in range(M))



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



    for a, b in queries:

        tree[a].add(b)

        tree[b].add(a)



    nn = 10 ** 9

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

    visited = {0}



    que = queue.Queue()



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



    while not que.empty():



        parent, current = que.get()



        if current in visited:

            continue



        visited.add(current)

        signs[current] = parent



        for t in tree[current]:

            if t in visited:

                continue

            else:

                que.put((current, t))



    return signs[2:]





def main():

    ans = solve()

    if 10**9 in ans:

        print('No')

    else:

        print('Yes')

        for a in ans:

            print(a)





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))



    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')

    for sign in signs[2:]:

        print(sign)





if __name__ == "__main__":

    main()

# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))
# import numpy as np
# from itertools import permutations
# from itertools import combinations
# from itertools import combinations_with_replacement
import queue

# import heapq
# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))
def solve():
    N, M = list(map(int, input().split()))
    queries = (list(map(int, input().split())) for _ in range(M))
    tree = [set() for _ in range(N + 1)]
    for a, b in queries:
        tree[a].add(b)
        tree[b].add(a)
    nn = 10**9
    signs = [nn for _ in range(N + 1)]
    visited = {0}
    que = queue.Queue()
    que.put((0, 1))  # parent, current
    while not que.empty():
        parent, current = que.get()
        if current in visited:
            continue
        visited.add(current)
        signs[current] = parent
        for t in tree[current]:
            if t in visited:
                continue
            else:
                que.put((current, t))
    return signs[2:]


def main():
    ans = solve()
    if 10**9 in ans:
        print("No")
    else:
        print("Yes")
        for a in ans:
            print(a)


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))
    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")
    for sign in signs[2:]:
        print(sign)


if __name__ == "__main__":
    main()

-# import sys -# readline = sys.stdin.readline -# generator = (readline().strip() for _ in range(N)) -# import numpy as np -# from itertools import permutations -# from itertools import combinations -# from itertools import combinations_with_replacement +import sys -# import heapq -# N, M = map(int, input().split()) -# As = list(map(int, input().split())) -# queries = (input() for _ in range(N)) -def solve(): -    N, M = list(map(int, input().split())) -    queries = (list(map(int, input().split())) for _ in range(M)) -    tree = [set() for _ in range(N + 1)] -    for a, b in queries: -        tree[a].add(b) -        tree[b].add(a) -    nn = 10**9 -    signs = [nn for _ in range(N + 1)] -    visited = {0} -    que = queue.Queue() -    que.put((0, 1))  # parent, current -    while not que.empty(): -        parent, current = que.get() -        if current in visited: -            continue -        visited.add(current) -        signs[current] = parent -        for t in tree[current]: -            if t in visited: -                continue -            else: -                que.put((current, t)) -    return signs[2:] +readline = sys.stdin.readline -    ans = solve() -    if 10**9 in ans: -        print("No") -    else: -        print("Yes") -        for a in ans: -            print(a) +    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 = 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") +    for sign in signs[2:]: +        print(sign)