from collections import deque



def main():

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



    edges = [[] for _ in range(n)]



    for _ in range(m):

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

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

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



    q = deque([0])



    ans = [-1]*n

    ans[0] = 0

    count = 1



    while q:

        l = q.popleft()

        for i in edges[l]:

            if ans[i] == -1:

                ans[i] = l

                count += 1

                q.append(i)

        if count == n:

            break



    if count == n:

        print('Yes')

        for i in ans[1:]:

            print((i+1))

    else:

        print('No')



if __name__ == '__main__':

    main()

from collections import deque

import sys

input = sys.stdin.readline



def main():

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



    edges = [[] for _ in range(n)]



    for _ in range(m):

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

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

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



    q = deque([0])



    ans = [-1]*n

    ans[0] = 0

    count = 1



    while q:

        l = q.popleft()

        for i in edges[l]:

            if ans[i] == -1:

                ans[i] = l

                count += 1

                q.append(i)

        if count == n:

            break



    if count == n:

        print('Yes')

        for i in ans[1:]:

            print((i+1))

    else:

        print('No')



if __name__ == '__main__':

    main()

from collections import deque


def main():
    n, m = list(map(int, input().split()))
    edges = [[] for _ in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split()))
        edges[a - 1].append(b - 1)
        edges[b - 1].append(a - 1)
    q = deque([0])
    ans = [-1] * n
    ans[0] = 0
    count = 1
    while q:
        l = q.popleft()
        for i in edges[l]:
            if ans[i] == -1:
                ans[i] = l
                count += 1
                q.append(i)
        if count == n:
            break
    if count == n:
        print("Yes")
        for i in ans[1:]:
            print((i + 1))
    else:
        print("No")


if __name__ == "__main__":
    main()

from collections import deque
import sys

input = sys.stdin.readline


def main():
    n, m = list(map(int, input().split()))
    edges = [[] for _ in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split()))
        edges[a - 1].append(b - 1)
        edges[b - 1].append(a - 1)
    q = deque([0])
    ans = [-1] * n
    ans[0] = 0
    count = 1
    while q:
        l = q.popleft()
        for i in edges[l]:
            if ans[i] == -1:
                ans[i] = l
                count += 1
                q.append(i)
        if count == n:
            break
    if count == n:
        print("Yes")
        for i in ans[1:]:
            print((i + 1))
    else:
        print("No")


if __name__ == "__main__":
    main()

+import sys + +input = sys.stdin.readline