import networkx as nx



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

G = nx.Graph()

for i in range(M):

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

    G.add_edge(A,B)

print("Yes")

pre = nx.predecessor(G,1)

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

    print((pre[i][0]))
from collections import deque



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

G = [[] for _ in range(N+1)]

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

pre = [1] * (N+1)

dist[0:2] = [0,0]

q = deque()



for i in range(M):

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

    G[A].append(B)

    G[B].append(A)

#print(G)    

q.append(1)

while q:

    v = q.popleft()

    for i in G[v]:

        if dist[i] != -1:

            continue

        dist[i] = pre[v] + 1

        pre[i] = v

        q.append(i)

print("Yes")

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

    print((pre[i]))
import networkx as nx

N, M = list(map(int, input().split()))
G = nx.Graph()
for i in range(M):
    A, B = list(map(int, input().split()))
    G.add_edge(A, B)
print("Yes")
pre = nx.predecessor(G, 1)
for i in range(2, N + 1):
    print((pre[i][0]))

from collections import deque

N, M = list(map(int, input().split()))
G = [[] for _ in range(N + 1)]
dist = [-1] * (N + 1)
pre = [1] * (N + 1)
dist[0:2] = [0, 0]
q = deque()
for i in range(M):
    A, B = list(map(int, input().split()))
    G[A].append(B)
    G[B].append(A)
# print(G)
q.append(1)
while q:
    v = q.popleft()
    for i in G[v]:
        if dist[i] != -1:
            continue
        dist[i] = pre[v] + 1
        pre[i] = v
        q.append(i)
print("Yes")
for i in range(2, N + 1):
    print((pre[i]))

-import networkx as nx +from collections import deque -G = nx.Graph() +G = [[] for _ in range(N + 1)] +dist = [-1] * (N + 1) +pre = [1] * (N + 1) +dist[0:2] = [0, 0] +q = deque() -    G.add_edge(A, B) +    G[A].append(B) +    G[B].append(A) +# print(G) +q.append(1) +while q: +    v = q.popleft() +    for i in G[v]: +        if dist[i] != -1: +            continue +        dist[i] = pre[v] + 1 +        pre[i] = v +        q.append(i) -pre = nx.predecessor(G, 1) -    print((pre[i][0])) +    print((pre[i]))