from collections import deque



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

rooms = [[] for i in range(n + 1)] #直接行ける部屋を記録



for i in range(m):

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

    rooms[a].append(b)

    rooms[b].append(a)



route = [-1]*(n + 1)

route[1] = 0

q = deque()

q.append(1)



while q:

    v = q.popleft()

    for i in rooms[v]:

        if route[i] == -1:

            route[i] = v

            q.append(i)



print("Yes")



for i in route[2:]:

    print(i)
from collections import deque

import sys

input = sys.stdin.readline



def main():

    N, M = list(map(int, input().split()))

    R = [[] for i in range(N + 1)]



    for i in range(M):

        A, B = list(map(int, input().split()))

        R[A].append(B)

        R[B].append(A)



    P = [-1] * (N + 1)

    P[1] = 0

    Q = deque()

    Q.append(1)



    while Q:

        v = Q.popleft()

        for r in R[v]:

            if P[r] == -1:

                P[r] = v

                Q.append(r)

    print('Yes')

    for p in P[2:]:

        print(p)

main()
from collections import deque

n, m = list(map(int, input().split()))
rooms = [[] for i in range(n + 1)]  # 直接行ける部屋を記録
for i in range(m):
    a, b = list(map(int, input().split()))
    rooms[a].append(b)
    rooms[b].append(a)
route = [-1] * (n + 1)
route[1] = 0
q = deque()
q.append(1)
while q:
    v = q.popleft()
    for i in rooms[v]:
        if route[i] == -1:
            route[i] = v
            q.append(i)
print("Yes")
for i in route[2:]:
    print(i)

from collections import deque
import sys

input = sys.stdin.readline


def main():
    N, M = list(map(int, input().split()))
    R = [[] for i in range(N + 1)]
    for i in range(M):
        A, B = list(map(int, input().split()))
        R[A].append(B)
        R[B].append(A)
    P = [-1] * (N + 1)
    P[1] = 0
    Q = deque()
    Q.append(1)
    while Q:
        v = Q.popleft()
        for r in R[v]:
            if P[r] == -1:
                P[r] = v
                Q.append(r)
    print("Yes")
    for p in P[2:]:
        print(p)


main()

+import sys -n, m = list(map(int, input().split())) -rooms = [[] for i in range(n + 1)]  # 直接行ける部屋を記録 -for i in range(m): -    a, b = list(map(int, input().split())) -    rooms[a].append(b) -    rooms[b].append(a) -route = [-1] * (n + 1) -route[1] = 0 -q = deque() -q.append(1) -while q: -    v = q.popleft() -    for i in rooms[v]: -        if route[i] == -1: -            route[i] = v -            q.append(i) -print("Yes") -for i in route[2:]: -    print(i) +input = sys.stdin.readline + + +def main(): +    N, M = list(map(int, input().split())) +    R = [[] for i in range(N + 1)] +    for i in range(M): +        A, B = list(map(int, input().split())) +        R[A].append(B) +        R[B].append(A) +    P = [-1] * (N + 1) +    P[1] = 0 +    Q = deque() +    Q.append(1) +    while Q: +        v = Q.popleft() +        for r in R[v]: +            if P[r] == -1: +                P[r] = v +                Q.append(r) +    print("Yes") +    for p in P[2:]: +        print(p) + + +main()