import queue

def main():

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

    ab = [[] for i in range(n)]

    for _ in range(m):

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

        ab[a-1].append(b-1)

        ab[b-1].append(a-1)

    q =queue.Queue()

    q.put(0)

    ans = [-1] * n

    ans[0] = 0

    while not q.empty():

        now = q.get()

        for i, next in enumerate(ab[now]):

            if ans[next] == -1:

                ans[next] = now+1

                q.put(next)

        

    print('Yes')

    for i in range(1,n):

        print((ans[i]))







if __name__=='__main__':

    main()

from collections import deque

def main():

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

    ab = [[] for i in range(n)]

    for _ in range(m):

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

        ab[a-1].append(b-1)

        ab[b-1].append(a-1)

    q = deque()

    q.append(0)

    ans = [-1] * n

    ans[0] = 0

    while len(q) != 0:

        now = q.popleft()

        for i, next in enumerate(ab[now]):

            if ans[next] == -1:

                ans[next] = now+1

                q.append(next)



    print('Yes')

    for i in range(1,n):

        print((ans[i]))







if __name__=='__main__':

    main()

import queue


def main():
    n, m = list(map(int, input().split()))
    ab = [[] for i in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split()))
        ab[a - 1].append(b - 1)
        ab[b - 1].append(a - 1)
    q = queue.Queue()
    q.put(0)
    ans = [-1] * n
    ans[0] = 0
    while not q.empty():
        now = q.get()
        for i, next in enumerate(ab[now]):
            if ans[next] == -1:
                ans[next] = now + 1
                q.put(next)
    print("Yes")
    for i in range(1, n):
        print((ans[i]))


if __name__ == "__main__":
    main()

from collections import deque


def main():
    n, m = list(map(int, input().split()))
    ab = [[] for i in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split()))
        ab[a - 1].append(b - 1)
        ab[b - 1].append(a - 1)
    q = deque()
    q.append(0)
    ans = [-1] * n
    ans[0] = 0
    while len(q) != 0:
        now = q.popleft()
        for i, next in enumerate(ab[now]):
            if ans[next] == -1:
                ans[next] = now + 1
                q.append(next)
    print("Yes")
    for i in range(1, n):
        print((ans[i]))


if __name__ == "__main__":
    main()

-import queue +from collections import deque -    q = queue.Queue() -    q.put(0) +    q = deque() +    q.append(0) -    while not q.empty(): -        now = q.get() +    while len(q) != 0: +        now = q.popleft() -                q.put(next) +                q.append(next)