import queue





def main():

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

    es = [[] for _ in range(n+1)]

    ans = [0 for _ in range(n+1)]



    for _ in range(m):

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

        es[a].append(b)

        es[b].append(a)



    q = queue.Queue()

    q.put(1)

    while not q.empty():

        p = q.get()



        for t in es[p]:

            if ans[t] > 0:

                continue

            ans[t] = p

            q.put(t)



    if 0 in ans[2:]:

        print("No")

    else:

        print("Yes")

        for a in ans[2:]:

            print(a)





if __name__ == '__main__':

    main()

from collections import deque





def main():

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

    es = [[] for _ in range(n+1)]

    ans = [0 for _ in range(n+1)]



    for _ in range(m):

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

        es[a].append(b)

        es[b].append(a)



    q = deque([1])

    while len(q) > 0:

        p = q.popleft()



        for t in es[p]:

            if ans[t] > 0:

                continue

            ans[t] = p

            q.append(t)



    if 0 in ans[2:]:

        print("No")

    else:

        print("Yes")

        for a in ans[2:]:

            print(a)





if __name__ == '__main__':

    main()

import queue


def main():
    n, m = list(map(int, input().split()))
    es = [[] for _ in range(n + 1)]
    ans = [0 for _ in range(n + 1)]
    for _ in range(m):
        a, b = list(map(int, input().split()))
        es[a].append(b)
        es[b].append(a)
    q = queue.Queue()
    q.put(1)
    while not q.empty():
        p = q.get()
        for t in es[p]:
            if ans[t] > 0:
                continue
            ans[t] = p
            q.put(t)
    if 0 in ans[2:]:
        print("No")
    else:
        print("Yes")
        for a in ans[2:]:
            print(a)


if __name__ == "__main__":
    main()

from collections import deque


def main():
    n, m = list(map(int, input().split()))
    es = [[] for _ in range(n + 1)]
    ans = [0 for _ in range(n + 1)]
    for _ in range(m):
        a, b = list(map(int, input().split()))
        es[a].append(b)
        es[b].append(a)
    q = deque([1])
    while len(q) > 0:
        p = q.popleft()
        for t in es[p]:
            if ans[t] > 0:
                continue
            ans[t] = p
            q.append(t)
    if 0 in ans[2:]:
        print("No")
    else:
        print("Yes")
        for a in ans[2:]:
            print(a)


if __name__ == "__main__":
    main()

-import queue +from collections import deque -    q = queue.Queue() -    q.put(1) -    while not q.empty(): -        p = q.get() +    q = deque([1]) +    while len(q) > 0: +        p = q.popleft() -            q.put(t) +            q.append(t)