import sys

from collections import deque



n, m = list(map(int, sys.stdin.readline().split()))



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

for _ in range(m):

    a, b = list(map(int, sys.stdin.readline().split()))

    to[a].append(b)

    to[b].append(a)

INF = float("inf")



dist = [INF] * (n + 1)

dist[1] = 0

pre = [0] * (n + 1)

que = deque([])

que.append(1)



while que:

    p = que.popleft()

    for i in to[p]:

        if dist[i] > dist[p] + 1:

            dist[i] = dist[p] + 1

            pre[i] = p

            que.append(i)



print("Yes")

for i in range(2, n + 1):

    print((pre[i]))
import sys

from collections import deque





def main():

    n, m = list(map(int, sys.stdin.readline().split()))



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

    for _ in range(m):

        a, b = list(map(int, sys.stdin.readline().split()))

        to[a].append(b)

        to[b].append(a)

    INF = float("inf")



    dist = [INF] * (n + 1)

    dist[1] = 0

    pre = [0] * (n + 1)

    que = deque([])

    que.append(1)



    while que:

        p = que.popleft()

        for i in to[p]:

            if dist[i] > dist[p] + 1:

                dist[i] = dist[p] + 1

                pre[i] = p

                que.append(i)



    print("Yes")

    for i in range(2, n + 1):

        print((pre[i]))





if __name__ == "__main__":

    main()
import sys
from collections import deque

n, m = list(map(int, sys.stdin.readline().split()))
to = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = list(map(int, sys.stdin.readline().split()))
    to[a].append(b)
    to[b].append(a)
INF = float("inf")
dist = [INF] * (n + 1)
dist[1] = 0
pre = [0] * (n + 1)
que = deque([])
que.append(1)
while que:
    p = que.popleft()
    for i in to[p]:
        if dist[i] > dist[p] + 1:
            dist[i] = dist[p] + 1
            pre[i] = p
            que.append(i)
print("Yes")
for i in range(2, n + 1):
    print((pre[i]))

import sys
from collections import deque


def main():
    n, m = list(map(int, sys.stdin.readline().split()))
    to = [[] for _ in range(n + 1)]
    for _ in range(m):
        a, b = list(map(int, sys.stdin.readline().split()))
        to[a].append(b)
        to[b].append(a)
    INF = float("inf")
    dist = [INF] * (n + 1)
    dist[1] = 0
    pre = [0] * (n + 1)
    que = deque([])
    que.append(1)
    while que:
        p = que.popleft()
        for i in to[p]:
            if dist[i] > dist[p] + 1:
                dist[i] = dist[p] + 1
                pre[i] = p
                que.append(i)
    print("Yes")
    for i in range(2, n + 1):
        print((pre[i]))


if __name__ == "__main__":
    main()

-n, m = list(map(int, sys.stdin.readline().split())) -to = [[] for _ in range(n + 1)] -for _ in range(m): -    a, b = list(map(int, sys.stdin.readline().split())) -    to[a].append(b) -    to[b].append(a) -INF = float("inf") -dist = [INF] * (n + 1) -dist[1] = 0 -pre = [0] * (n + 1) -que = deque([]) -que.append(1) -while que: -    p = que.popleft() -    for i in to[p]: -        if dist[i] > dist[p] + 1: -            dist[i] = dist[p] + 1 -            pre[i] = p -            que.append(i) -print("Yes") -for i in range(2, n + 1): -    print((pre[i])) + +def main(): +    n, m = list(map(int, sys.stdin.readline().split())) +    to = [[] for _ in range(n + 1)] +    for _ in range(m): +        a, b = list(map(int, sys.stdin.readline().split())) +        to[a].append(b) +        to[b].append(a) +    INF = float("inf") +    dist = [INF] * (n + 1) +    dist[1] = 0 +    pre = [0] * (n + 1) +    que = deque([]) +    que.append(1) +    while que: +        p = que.popleft() +        for i in to[p]: +            if dist[i] > dist[p] + 1: +                dist[i] = dist[p] + 1 +                pre[i] = p +                que.append(i) +    print("Yes") +    for i in range(2, n + 1): +        print((pre[i])) + + +if __name__ == "__main__": +    main()