from collections import deque



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

adj=[[] for _ in range(n)]

for _ in range(m):

  x,y=list(map(int,input().split()))

  adj[x-1].append(y-1)

  adj[y-1].append(x-1)



before=[None] * n

before[0] = -1

q=deque([0])

while len(q):

  node=q.popleft()

  for nxt in adj[node]:

    if before[nxt] is not None:

      continue

    q.append(nxt)

    before[nxt] = node

print("Yes")

for i in range(1, n):

  print((before[i] + 1))



  
from collections import deque



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

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

for i in range(M):

    A_tmp , B_tmp = list(map(int, input().split()))

    AB[A_tmp].append(B_tmp)

    AB[B_tmp].append(A_tmp)



ans = [0]*(N+1)

visited = [False] * (N + 1)



q = deque()

q.append((1, -1))

while len(q) > 0:

    node, past = q.popleft()

    if visited[node]:

      continue

    ans[node] = past

    visited[node] = True

    for t in AB[node]:

        if visited[t]:

            continue

        q.append((t, node))

print("Yes")

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

    print((ans[i]))

from collections import deque

n, m = list(map(int, input().split()))
adj = [[] for _ in range(n)]
for _ in range(m):
    x, y = list(map(int, input().split()))
    adj[x - 1].append(y - 1)
    adj[y - 1].append(x - 1)
before = [None] * n
before[0] = -1
q = deque([0])
while len(q):
    node = q.popleft()
    for nxt in adj[node]:
        if before[nxt] is not None:
            continue
        q.append(nxt)
        before[nxt] = node
print("Yes")
for i in range(1, n):
    print((before[i] + 1))

from collections import deque

N, M = list(map(int, input().split()))
AB = [[] for _ in range(N + 1)]
for i in range(M):
    A_tmp, B_tmp = list(map(int, input().split()))
    AB[A_tmp].append(B_tmp)
    AB[B_tmp].append(A_tmp)
ans = [0] * (N + 1)
visited = [False] * (N + 1)
q = deque()
q.append((1, -1))
while len(q) > 0:
    node, past = q.popleft()
    if visited[node]:
        continue
    ans[node] = past
    visited[node] = True
    for t in AB[node]:
        if visited[t]:
            continue
        q.append((t, node))
print("Yes")
for i in range(2, N + 1):
    print((ans[i]))

-n, m = list(map(int, input().split())) -adj = [[] for _ in range(n)] -for _ in range(m): -    x, y = list(map(int, input().split())) -    adj[x - 1].append(y - 1) -    adj[y - 1].append(x - 1) -before = [None] * n -before[0] = -1 -q = deque([0]) -while len(q): -    node = q.popleft() -    for nxt in adj[node]: -        if before[nxt] is not None: +N, M = list(map(int, input().split())) +AB = [[] for _ in range(N + 1)] +for i in range(M): +    A_tmp, B_tmp = list(map(int, input().split())) +    AB[A_tmp].append(B_tmp) +    AB[B_tmp].append(A_tmp) +ans = [0] * (N + 1) +visited = [False] * (N + 1) +q = deque() +q.append((1, -1)) +while len(q) > 0: +    node, past = q.popleft() +    if visited[node]: +        continue +    ans[node] = past +    visited[node] = True +    for t in AB[node]: +        if visited[t]: -        q.append(nxt) -        before[nxt] = node +        q.append((t, node)) -for i in range(1, n): -    print((before[i] + 1)) +for i in range(2, N + 1): +    print((ans[i]))