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 q:

        now = q.popleft()

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

            if ans[next] == -1:

                ans[next] = now+1

                q.append(next)

        if len(q) == 0:

            break

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

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

    for _ in range(m):

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

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

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

    q = deque()

    q.append(0)

    ans = [-1] * n

    ans[0] = 0

    while q:

        now = q.popleft()

        for i in arr[now]:

            if ans[i] == -1:

                ans[i] = now+1

                q.append(i)

        if len(q) == 0:

            break

    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 q:
        now = q.popleft()
        for i, next in enumerate(ab[now]):
            if ans[next] == -1:
                ans[next] = now + 1
                q.append(next)
        if len(q) == 0:
            break
    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()))
    arr = [[] for i in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split()))
        arr[a - 1].append(b - 1)
        arr[b - 1].append(a - 1)
    q = deque()
    q.append(0)
    ans = [-1] * n
    ans[0] = 0
    while q:
        now = q.popleft()
        for i in arr[now]:
            if ans[i] == -1:
                ans[i] = now + 1
                q.append(i)
        if len(q) == 0:
            break
    print("Yes")
    for i in range(1, n):
        print((ans[i]))


if __name__ == "__main__":
    main()

-    ab = [[] for i in range(n)] +    arr = [[] for i in range(n)] -        ab[a - 1].append(b - 1) -        ab[b - 1].append(a - 1) +        arr[a - 1].append(b - 1) +        arr[b - 1].append(a - 1) -        for i, next in enumerate(ab[now]): -            if ans[next] == -1: -                ans[next] = now + 1 -                q.append(next) +        for i in arr[now]: +            if ans[i] == -1: +                ans[i] = now + 1 +                q.append(i)