There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.
 - If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.

-----Constraints-----
 - All values in input are integers.
 - 2 \leq N \leq 10^5
 - 1 \leq M \leq 2 \times 10^5
 - 1 \leq A_i, B_i \leq N\ (1 \leq i \leq M)
 - A_i \neq B_i\ (1 \leq i \leq M)
 - One can travel between any two rooms by traversing passages.

-----Input-----
Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M

-----Output-----
If there is no way to place signposts satisfying the objective, print No.
Otherwise, print N lines. The first line should contain Yes, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i.

-----Sample Input-----
4 4
1 2
2 3
3 4
4 2

-----Sample Output-----
Yes
1
2
2

If we place the signposts as described in the sample output, the following happens:
 - Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \to 1. This is the minimum number of passages possible.
 - Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \to 2 \to 1. This is the minimum number of passages possible.
 - Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \to 2 \to 1. This is the minimum number of passages possible.
Thus, the objective is satisfied.

Difficulty: interview

Starter code:

Solutions:
from collections import deque

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
link = [[] for _ in range(N)]

for i in range(M):
    link[L[i][0]-1].append(L[i][1]-1)
    link[L[i][1]-1].append(L[i][0]-1)

checked = [-1 for _ in range(N)]
checked[0] = 0
d = deque([0])
while d:
    now = d.popleft()
    for i in range(len(link[now])):
        if checked[link[now][i]] == -1:
            checked[link[now][i]] = now + 1
            d.append(link[now][i])


flag = False
for i in range(1, N):
    if checked[i] == -1:
        flag = True
        break

if flag:
    print('No')
else:
    print('Yes')
    for i in range(1, N):
        print(checked[i])

from collections import deque
n,m=list(map(int,input().split()))
r=[[] for i in range(n+1)]
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)
    R[a].append(b)
    R[b].append(a)
dep=[-1]*(n+1)
dep[0]=0
dep[1]=0
data=deque([1])
d=0
while len(data)>0:
    p=data.popleft()
    for i in r[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            data.append(i)
    r[p]=[]
if not all(dep[i+1]>=0 for i in range(n)):
    print("No")
else:
    print("Yes")
    for i in range(2,n+1):
        for j in R[i]:
            if dep[j]==dep[i]-1:
                print(j)
                break


from collections import deque
N,M = list(map(int,input().split()))

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

for i in range(M):
    a,b = list(map(int,input().split()))
    A[a].append(b)
    A[b].append(a)

def BFS():
    q = deque()
    q.append(1)
    pre = [0] * (N+1)
    pre[0] = pre[1] = -1
    while(q):
        x = q.popleft()
        for y in A[x]:
            if pre[y] == 0:
                pre[y] = x 
                q.append(y)
    if 0 in pre:
        print('No')
    else:
        print('Yes')
        for i in range(2,N+1):
            print((pre[i]))

BFS()
            
            
            


N,M=map(int,input().split())
V=[[]for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    V[a-1].append(b-1)
    V[b-1].append(a-1)
print('Yes')
p,q=0,[0]
seen=[0]*N
d=[0]*N
while len(q)!=p:
    for i in V[q[p]]:
        if not seen[i]:
            q.append(i)
            d[i]=q[p]+1
        seen[i]+=1
    p+=1
d.pop(0)
for i in d:print(i)

from collections import deque
N, M = list(map(int, input().split()))
roads = []
for _ in range(N):
    roads.append([])
for _ in range(M):
    a, b = list(map(int, input().split()))
    roads[a - 1].append(b - 1)
    roads[b - 1].append(a - 1)
visited = [float('inf')] * N
q = deque()
q.append(0)
visited[0] = 0
pre = [-1] * N
while q:
    now_room = q.popleft()
    for next_room in roads[now_room]:
        if visited[next_room] != float('inf'):
            continue
        visited[next_room] = visited[now_room] + 1
        if pre[next_room] == -1:
            pre[next_room] = now_room + 1
        q.append(next_room)
# print(*roads)
# print(*pre)

print('Yes')
for i in range(1, N):
    print((pre[i]))


from collections import defaultdict, deque

N, M = list(map(int, input().split()))
edges = defaultdict(list)
for _ in range(M):
    a, b = [int(x)-1 for x in input().split()]
    edges[a].append(b)
    edges[b].append(a)

go_to = [None] * N

q = deque()
q.append((0, -1))
is_visited = set()

while q:
    node, prev = q.popleft()
    if node in is_visited:
        continue
    is_visited.add(node)
    go_to[node] = prev + 1
    for dest in edges[node]:
        q.append((dest, node))

print('Yes')
for i in range(1, N):
    print((go_to[i]))



N,M=map(int,input().split())
from collections import deque

g=[[] for _ in range(N+1)]
for _ in range(M):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)

def bfs(u):
    queue = deque([u])
    ans = [None] * (N+1) # 距離が1小さい隣接点
    d = [None] * (N+1) # uからの距離の初期化
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                ans[i] = v
                queue.append(i)
    return ans

# 0からの各頂点の距離
ans = bfs(1)
print('Yes')
for i in range(2,N+1):
    print(ans[i])

from collections import deque
n, m = map(int, input().split())
route = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    route[a].append(b)
    route[b].append(a)
dist = [0]*(n+1)
dist[0] = 0
dist[1] = 0

d = deque()
d.append(1)
ans = [0 for _ in range(n+1)]
while d:
    v = d.popleft()
    for i in route[v]:
        if dist[i] != 0:
            continue
        dist[i] = dist[v]+1
        ans[i] = v
        d.append(i)

if len(dist[2:]) > 0:
    print('Yes')
    print(*ans[2:], sep="\n")
else:
    print('No')


from collections import deque
N,M=map(int,input().strip().split())
l=[]
dp=[[] for _ in range(N)]
for _ in range(M):
    a,b=map(int,input().strip().split())
    l.append((a,b))
    dp[a-1].append(b)
    dp[b-1].append(a)

d=deque([1])
visited=[0 for _ in range(N)]
visited[0]=1
cnt=1
while d:
    tmp=d.popleft()
    for e in dp[tmp-1]:
        if visited[e-1]==0:
            visited[e-1]=tmp
            cnt+=1
            d.append(e)
            
if cnt!=len(visited):
    print("No")
else:
    print("Yes")
    for n in range(1,N):
        print(visited[n])

import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,m = LI()
    route = [None] + [[] for _ in range(n)]
    for _ in range(m):
        a,b = LI()
        route[a].append(b)
        route[b].append(a)

    explored = {1}
    queue = collections.deque([1])
    ans = [None for _ in range(n+1)]
    while len(queue)!=0:
        nxt = queue.popleft()
        for nbh in route[nxt]:
            if nbh not in explored:
                ans[nbh] = nxt
                queue.append(nbh)
                explored.add(nbh)
    print("Yes")
    print(*ans[2:],sep="\n")
        
main()            


N, M=map(int, input().split())
g = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    g[a].append(b)
    g[b].append(a)


from collections import deque

queue=deque([1])
d=[None]*(N+1)
d[1]=0
ans=[0]*(N+1)
while queue:
    v=queue.popleft()
    for i in g[v]:
        if d[i] is None:
            d[i]=d[v]+1
            ans[i]=v
            queue.append(i)

            
print("Yes")
for i in range(2,len(ans)):
    print(ans[i])

from collections import deque
N,M=map(int,input().split())
adjacent=[set() for x in range(N)]
for m in range(M):
    A,B=map(int,input().split())
    adjacent[A-1].add(B-1)
    adjacent[B-1].add(A-1)
ans=[0]*N
deque1=deque()
already=set()
already.add(0)
num_already=1
for j in adjacent[0]:
    deque1.append(j)
    already.add(j)
    num_already+=1
    ans[j]=1
while(num_already!=N):
    now=deque1.popleft()
    for k in adjacent[now]:
        if k not in already:
            num_already+=1
            already.add(k)
            ans[k]=now+1
            deque1.append(k)
print("Yes")
for i in range(1,N):
    print(ans[i])

from collections import deque
n,m=map(int,input().split())
edge=[[] for _ in range(n)]
for i in range(m):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
dist=[-1]*n
d=deque()
d.append(0)
now=0
while d:
    x=d.popleft()
    for i in range(len(edge[x])):
        if dist[edge[x][i]]==-1:
            dist[edge[x][i]]=x+1
            d.append(edge[x][i])
print("Yes")
for i in range(n-1):
    print(dist[i+1])

from collections import deque
N, M = list(map(int, input().split()))
G = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = list(map(int, input().split()))
    G[a].append(b)
    G[b].append(a)
q = deque([1])
closed = [False] * (N+1)
closed[1] = True
Ans = [0] * (N+1)
while q:
    v = q.popleft()
    for u in G[v]:
        if not closed[u]:
            closed[u] = True
            q.append(u)
            Ans[u] = v
print("Yes")
print(("\n".join(map(str, Ans[2:]))))


from collections import deque

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

route = [[] for i in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    route[a - 1].append(b - 1)
    route[b - 1].append(a - 1)

print('Yes')

q = deque()
d = [-1] * N
d[0] = 0
q.append(0)

while q:
    x = q.popleft()
    for i in route[x]:
        if d[i] == -1:
            d[i] = x + 1
            q.append(i)

for i in range(1, N):
    print((d[i]))


from collections import deque

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

ans = [-1 for _ in range(n+1)]
ans[0] = 0
ans[1] = 0

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

for _ in range(m):
    x, y = map(int, input().split())
    V[x].append(y)
    V[y].append(x)

d = deque([1])

while d:
    l = d.popleft()
    for v in V[l]:
        if ans[v] != -1:
            continue
        ans[v] = l
        d.append(v)
        

    
if ans.count(-1) > 0:
    print('No')
else :
    print('Yes')
    print(*ans[2:], sep="\n")


from sys import stdin,stdout
from collections import defaultdict
def bfs(src):
    q=[src]
    par=[-1]*(n+1)
    vis=[0]*(n+1)
    ans=[]
    while q:
        cur=q.pop(0)
        for neigh in g[cur]:
            if not vis[neigh]:
                vis[neigh]=1
                q+=[neigh]
                par[neigh]=cur
    for i in range(2,n+1):
        if par[i]==-1:
            print('No')
            return
        ans+=[par[i]]
    print('Yes')
    for v in ans:
        print(v)
for i in range(1):#int(stdin.readline())):
    # n=int(stdin.readline())
    g=defaultdict(list)
    n,e=list(map(int,stdin.readline().split()))
    for _ in range(e):
        a,b=map(int,stdin.readline().split())
        g[a]+=[b]
        g[b]+=[a]
    bfs(1)

from collections import deque
INF = 1_000_000_000
def main():
    n, m = map(int, input().split(" "))
    to = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(lambda i:int(i)-1, input().split(" "))
        to[a].append(b)
        to[b].append(a)
    que = deque()
    d = {i:INF for i in range(n)}
    prev = {i:-1 for i in range(n)}
    d[0] = 0
    que.append(0)
    while que:
        v = que.popleft()
        for i in to[v]:
            if d[i] != INF: continue
            d[i] = d[v] + 1
            prev[i] = v
            que.append(i)
    print("Yes")
    for i in range(n):
        if i == 0: continue
        print(prev[i]+1)
        
def __starting_point():
    main()
__starting_point()

from collections import deque

n,m = map(int,input().split())
to = [[] for _ in range(n)]

for i in range(m):
    x, y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)

INF = float('inf')
dist = [INF]*n
dist[0] = 0

pre = [-1]*n

que = deque([])
que.append(0)

while que:
    v = que.popleft()
    for u in to[v]:
        if dist[u] != INF:continue
        dist[u] = v + 1
        pre[u] = v
        que.append(u)
print("Yes")
for i in range(1,n):
    print(dist[i])

#import math
import collections
n, m = map(int, input().split( ))
lis = [[] for _ in range(n+1)]
for _ in range(m):
  a,b = map(int, input().split( ))
  lis[a].append(b)
  lis[b].append(a)
#print(lis)
ans = [0]*(n+1)
q = collections.deque()
q.append(1)
count = [0]*(n+1)
#1の時は動かない
count[1] = 1
while len(q) != 0:
  v = q.popleft()
#  print(lis[v], count)
  #まずは1につながっている部屋を探索その後順に探索
  for u in lis[v]:
    if count[u] == 0:
      count[u] = 1
      ans[u] = v
      q.append(u)
print('Yes')
for i in range(2,n+1):
  print(ans[i])

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

to = [[] for i in range(100010)]

for i in range(M):
    a, b = list(map(int, input().split()))
    to[a].append(b)
    to[b].append(a)

dist = [0] * (N+1)
q = [1]
dist[0] = -1
#print(to[:4])

dist = [0] * N
pre = [0] * N

while len(q) != 0:
    a = q.pop(0)
    for i in to[a]:
        if dist[i-1] == 0:
            dist[i-1] = dist[a-1] + 1
            pre[i-1] = a
            q.append(i)
    #print(q)

print("Yes")
for i in range(1, N):
    print((pre[i]))



import sys
input = sys.stdin.readline
from collections import deque
import marshal


class Graph:
    def __init__(self, n, directed=False, decrement=True, destroy=False, edges=[]):
        self.n = n
        self.directed = directed
        self.decrement = decrement
        self.destroy = destroy
        self.edges = [set() for _ in range(self.n)]
        self.parent = [-1]*self.n
        self.info = [-1]*self.n
        for x, y in edges:
            self.add_edge(x,y)

    def add_edge(self, x, y):
        if self.decrement:
            x -= 1
            y -= 1
        self.edges[x].add(y)
        if self.directed == False:
            self.edges[y].add(x)

    def add_adjacent_list(self, i, adjacent_list):
        if self.decrement:
            self.edges[i] = set(map(lambda x: x - 1, adjacent_list))
        else:
            self.edges[i] = set(adjacent_list)

    def bfs(self, start=1, goal=-1, time=0, save=False):
        """
        :param start: スタート地点
        :param goal: ゴール地点
        :param save: True = 前回の探索結果を保持する
        :return: （ループがあっても）最短距離。存在しなければ -1
        """
        if self.decrement:
            start -= 1
            goal -= 1
        if not save:
            self.parent = [-1] * self.n
        p, t = start, time
        self.parent[p] = -2
        next_set = deque([(p, t)])

        while next_set:
            p, t = next_set.popleft()
            for q in self.edges[p]:
                if self.parent[q] != -1:
                    continue
                if q == goal:
                    return t + 1
                self.parent[q] = p
                next_set.append((q, t + 1))
        return -1

    def connection_counter(self):
        """
        :return: 連結成分の個数。有効グラフではあまり意味がない。
        """
        cnt = 0
        self.parent = [-1] * self.n
        for start in range(self.n):
            if self.parent[start] == -1:
                cnt += 1
                self.bfs(start + self.decrement, save=True)
        return cnt

    def distance_list(self, start=1, save=False):
        """
        :param start: スタート地点
        :return: スタート地点から各点への距離のリスト
        """
        dist = [-1]*self.n
        if self.decrement:
            start -= 1
        if not save:
            self.parent = [-1] * self.n
        p, t = start, 0
        self.parent[p] = -2
        dist[p] = 0
        next_set = deque([(p, t)])

        while next_set:
            p, t = next_set.popleft()
            for q in self.edges[p]:
                if self.parent[q] != -1:
                    continue
                dist[q] = t + 1
                self.parent[q] = p
                next_set.append((q, t + 1))
        return dist

##################################################################################################

N, M = map(int, input().split())
graph = Graph(N, directed=False, decrement=True, destroy=False)
for _ in range(M):
    x, y = map(int, input().split())
    graph.add_edge(x, y)

if -1 in graph.distance_list():
    print("No")
else:
    print("Yes")
    print(*list(p+1 for p in graph.parent[1:]), sep="\n")


from collections import deque
n,m = map(int, input().split())
dis = [n+2]*(n)
dis[0] = 0
near = [[] for _ in range(n)]
mark = [-1]*(n)
mark[0] = 0
que = deque()
for _ in range(m):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  near[a].append(b)
  near[b].append(a)
  if a==0:
    que.appendleft(b)
    mark[b] = 0
    dis[b] = 1
  if b==0:
    que.appendleft(a)
    mark[a] = 0
    dis[a] = 1
while que:
  i = que.popleft()
  for j in near[i]:
    if dis[i]+1<dis[j]:
      dis[j] = dis[i]+1
      mark[j] = i
      que.append(j)
if n+2 not in dis:
  print('Yes')
  for i in mark[1:]:
    print(i+1)
else:
  print('No')

# 幅優先探索, BFS

from collections import deque

n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]

neighbor = [[] for _ in range(n)]
for edge in edges:
    neighbor[edge[0]-1].append(edge[1]-1)  # 1- → 0-index
    neighbor[edge[1]-1].append(edge[0]-1)

queue = deque()
queue.append(0)

back = [-1] * n  # visitしたかどうかを兼ねる
back[0] = 0
while len(queue) > 0:
    vertex = queue.popleft()
    for nei in neighbor[vertex]:
        if back[nei] == -1:
            back[nei] = vertex
            queue.append(nei)
        
print('Yes')
for i in back[1:]:
    print((i+1))  # 0- → 1-index


from collections import deque


def show_2d_array(array):
    [print(a) for a in array]


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

cave = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    cave[a-1].append(b-1)
    cave[b-1].append(a-1)


# show_2d_array(cave)


def bfs(tree, p):
    seen = [False] * len(tree)
    queue = deque((p,))
    depth = [0] * N
    depth[p] = 0
    current_depth = depth[p]
    while len(queue) > 0:
        # print(queue)
        q = queue.popleft()
        seen[q] = True
        # print(q)
        for v in tree[q]:
            if not seen[v]:
                depth[v] = depth[q] + 1
                queue.append(v)
                seen[v] = True


    return depth


depth = bfs(cave, 0)

# print("depth", depth)

sign = [0] * N
ans = "Yes"
for i in range(1, N):
    this_depth = depth[i]
    found = False
    for j in cave[i]:
        if depth[j] == this_depth - 1:
            sign[i] = j
            found = True
            break
    if not found:
        ans = "No"
        break

"""
for i in range(1, N):
    current = i
    found = False
    while not found:
        next = -1
        for j in cave[current]:
            if depth[j] == depth[current]-1:
                if sign[current] <= 0:
                    next = j
                    sign[current] = next
                    break
                else:
                    next = sign[current]
                    break
        if next < 0:
            ans = "No"
            break

        current = next
        if current == 0:
            found = True
"""

print(ans)
if ans == "Yes":
    [print(s+1) for s in sign[1:]]



from collections import*
(n,m),*c = [[*map(int,i.split())]for i in open(0)]
g = [[]for _ in range(n+1)]

for a,b in c:
    g[a]+=[b]
    g[b]+=[a]

q=deque([1])
r=[0]*(n+1)

while q:
    v=q.popleft()
    for i in g[v]:
        if r[i]==0:
            r[i]=v
            q.append(i)

print("Yes",*r[2:],sep="\n")


from collections import deque
infty = 10 ** 9

def BFS(graph, parent, u):
    queue = deque()
    queue.append(u)
    visited = [False for k in range(len(parent))] #探索が始まったか否か
    visited[u] = True
    while queue:
        v = queue.popleft()
        for j in graph[v]:
            if not visited[j]:
                queue.append(j)
                visited[j] = True
                parent[j] = v

n, m = map(int, input().split())
graph = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
parent = [-1 for i in range(n)]
BFS(graph, parent, 0)
if -1 in parent[1:]:
    print("No")
else:
    print("Yes")
    for p in parent[1:]:
        print(p+1)

from heapq import heappush, heapify, heappop


def dijkstra(start: "始点", V: "頂点数", es: "隣接リスト", INF=10000000000):
    # INF = 10**10 毎回チェックしよう
    prev = [-1] * n  # 経路復元
    d = [INF] * n  # 頂点sからの最短距離
    que = [start]
    d[start] = 0
    while que:
        dv, v = divmod(heappop(que), INF)
        if d[v] < dv:
            continue
        for e, de in es[v]:
            if d[e] > d[v] + de:
                d[e] = d[v] + de
                heappush(que, d[e] * INF + e)
                prev[e] = v
    return d, prev


def get_path(t, prev):
    path = []
    while t != -1:
        path.append(t)
        t = prev[t]
    path.reverse()
    return path


n, m = list(map(int, input().split()))
es = [[] for _ in range(n)]  # es[i] = (頂点iの(隣接する頂点,コスト)の組)
# 入力
for i in range(m):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    es[a].append((b, 1))
    es[b].append((a, 1))  # 無向グラフ


d, prev = dijkstra(0, n, es)
print("Yes")
for i in range(1, n):
    print((prev[i] + 1))


N,M = map(int,input().split())
t = [[i+1] for i in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    t[A-1].append(B)
    t[B-1].append(A)
from collections import deque
d = deque()
ans = [-1]*(N)
d.append(t[0])
while len(d) > 0:
    z = d.popleft()
    x = z[0]
    for i in range(1,len(z)):
        if ans[z[i]-1] == -1:
            ans[z[i]-1] = x
            d.append(t[z[i]-1])
print("Yes")
for i in range(1,len(ans)):
    print(ans[i])

from collections import deque

n,m = list(map(int,input().split()))
a = [[] for _ in range(n)]

for i in range(m):
    x, y = list(map(int,input().split()))
    a[x-1].append(y-1)
    a[y-1].append(x-1)

c = [0]*n
que = deque([])
que.append(0)

while len(que) > 0:
    e = que.popleft()
    for i in a[e]:
        if c[i] > 0:
            continue
        c[i] = e + 1
        que.append(i)
print("Yes")
for i in range(1,n):
    print((c[i]))


from collections import deque
n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
    a = list(map(int, input().split()))
    g[a[0]-1].append(a[1]-1)
    g[a[1]-1].append(a[0]-1)
l = [True] * n
ans = [0] * n
x = deque([1])
while len(x) > 0:
    a = x.popleft()
    for i in g[a-1]:
        if l[i]:
            x.append(i+1)
            ans[i] = a
            l[i] = False
if l.count(True) == 0:
    print("Yes")
    for i in range(1, n):
        print(ans[i])
else:
    print("No")

from collections import deque

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

umami = [[] for _ in range(N+1)]
for a, b in AB:
    umami[a].append(b)
    umami[b].append(a)

umaaji = [0]*(N+1)
d = deque([1])
while d:
    r = d.popleft()
    for u in umami[r]:
        if umaaji[u] == 0:
            umaaji[u] = r
            d.append(u)

print("Yes")
for u in umaaji[2:]:
    print(u)

from collections import deque
n, m = list(map(int, input().split()))

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

for i in range(m):
  _, __ = list(map(int, input().split()))
  _ -= 1
  __ -= 1
  adj_list[_].append(__)
  adj_list[__].append(_)
  
distance = [None for i in range(n)]
updated_from = [None for i in range(n)]

newly_visited = deque([0])
distance[0] = 0

while len(newly_visited) > 0:
  now = newly_visited.popleft()
  for i in adj_list[now]:
    if distance[i] is not None: continue
    newly_visited.append(i)
    distance[i] = distance[now] + 1
    updated_from[i] = now

# i に到達できてれば distance[i] ==（0 から i までの距離）
# i に到達できてなければ distance[i] == None   
    
"""
print(distance)

for i in range(n):
  # i から 0 に行く経路を求める
  now = i
  path = [now]
  while now != 0:
    now = updated_from[now]
    path.append(now)
  print(i, path) 
"""

print("Yes")
for i in range(1, n):
  print((updated_from[i] + 1))




from collections import deque

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

dist = [-1] * (N+1)
dist[1] = 0
connection = [[] for _ in range(N+1)]
ans = [-1] * (N+1)

for quel in range(M):
    a, b = map(int, input().split())
    connection[a].append(b)
    connection[b].append(a)

que = deque()
que.append(1)

while que:
    v = que.popleft()

    for i in connection[v]:
        if dist[i] != -1:continue

        dist[i] = dist[v] + 1
        que.append(i)
        ans[i] = v

#print(dist)
print('Yes')
for j in range(2, N+1):
    print(ans[j])

from collections import deque
N, M = map(int, input().split())

graph = [[] for _ in range(N)]
flag = [0] * N

for i in range(M):
  A, B = map(int, input().split())
  A -= 1
  B -= 1
  graph[A].append(B)
  graph[B].append(A)
  
D = deque([0])
visited = [False] * N
visited[0] = True

while D:
  v = D.popleft()
  for i in graph[v]:
    if visited[i]:
      continue
    visited[i] = True
    flag[i] = v
    D.append(i)
    
print("Yes")
for i in range(1, N):
  print(flag[i] + 1)

from collections import deque

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,m=input2()
g=[[] for _ in range(n+1)] #引数->要素で道しるべを保存
for i in range(m):
	a,b=input2()
	g[a].append(b)
	g[b].append(a)

q=deque() #bfs用
q.append(1) #始点

check=[0]*(n+1) #既に訪問している(1)か否(0)か
check[1]=1

ans=[0]*(n+1) #始点に近い側の，一つ前の要素(解答)
ans[1]=1
for _ in range(10**5+1):
	if len(q)==0:
		break
	v=q.popleft() #頂点を一つ取り出す
	for u in g[v]: #vとの通路を全て探索
		if check[u]==0: 
			check[u]=1 #探索済み==1
			ans[u]=v 
			q.append(u)
print("Yes")
for i in range(2,n+1):
	print(ans[i])

from collections import deque

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

G = [[] for _ in range(N+1)]
m = [tuple(map(int, input().split())) for _ in range(M)]

for a, b in m:
    G[a].append(b)
    G[b].append(a)

par = [0] * (N + 1)
visited = [0] * (N + 1)
root = 1
visited[root] = 1
q = deque([root])

while q:
    v = q.popleft()
    for w in G[v]:
        if visited[w]:
            continue
        visited[w] = 1
        par[w] = v
        q.append(w)
print('Yes')
print(*par[2:], sep='\n')
    

#!/usr/bin/env python3

#import
#import math
#import numpy as np
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

G = {i: [] for i in range(1, N + 1)}
seen = [False] * (N + 1)

for a, b in AB:
    G[a].append(b)
    G[b].append(a)

dp = [10 ** 9] * (N + 1)
dp[1] = 0

que = []
que.append(1)
while len(que) > 0:
    q = que.pop(0)
    for g in G[q]:
        if not seen[g]:
            seen[g] = True
            que.append(g)
        dp[g] = min(dp[g], dp[q] + 1)

print("Yes")
for i in range(2, N + 1):
    t = dp[i]
    for g in G[i]:
        if dp[g] < t:
            print(g)
            break

n,m = map(int,input().split())
r = [[] for _ in range(n+1)]

for _ in range(m):
    a,b = map(int,input().split())
    r[a].append(b)
    r[b].append(a)

import collections
q = collections.deque()

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

for i in r[1]:
    q.append((1,i))
    
while q:
    xy = q.popleft()
    x = xy[0]
    y = xy[1]
    
    if sigh[y] == -1:
        sigh[y] = x
        
        for i in r[y]:
            q.append([y,i])
            
print("Yes")
print(*sigh[2:],sep="\n")

from collections import deque
N,M=map(int,input().split())
A=[0]*M;B=[0]*M
C=[[] for i in range(N+1)]

for i in range(M):
  A[i],B[i]=sorted(list(map(int,input().split())))
  C[A[i]].append(B[i])
  C[B[i]].append(A[i])

d=[-1]*(N+1)
d[0]=0
d[1]=0

queue=deque([1])
while queue:
  now = queue.popleft()
  for i in C[now]:
    if d[i]!=-1:continue
    d[i]=now
    queue.append(i)

if d.count(0)>2:print('No');exit
print('Yes')
for i in range(2,N+1):
  print(d[i])

# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 21:29:58 2020

@author: liang
"""

N, M = map(int, input().split())
adj = [list() for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)

visited = [False for i in range(N)]
sign = [-1]*N

from collections import deque

visited[0] = True
q = deque()
q.append(0)
sign[0] = 0

while q:
    cur = q.popleft()
    for a in adj[cur]:
        if not visited[a]:
            visited[a] = True
            sign[a] = cur + 1
            q.append(a)

if all(x >= 0 for x in sign):
    print("Yes")
    [print(a) for a in sign[1:] ]
else:
    print("No")    

import sys
readline = sys.stdin.readline

N,M = list(map(int,readline().split()))
G = [[] for i in range(N)]
for i in range(M):
  a,b = list(map(int,readline().split()))
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)

# 1の部屋からBFSして、初めて来た部屋だったら直前の部屋番号(+1)を入れる
ans = [None] * N

from collections import deque
q = deque([])

q.append((0, -1))
while q:
  v, parent = q.popleft()
  if ans[v] is not None:
    continue
  ans[v] = parent + 1
  for child in G[v]:
    if child == parent:
      continue
    q.append((child, v))

print("Yes")
for i in range(1, len(ans)):
  print((ans[i]))


def main():
	N, M = [int(x) for x in input().split(" ")]
	route = [[] for i in range(N)]
	for i in range(M):
		A, B = [int(y) for y in input().split(" ")]
		route[A - 1] += [B]
		route[B - 1] += [A]

	checked = [1] + [0] * (N - 1)
	to_check = [{"src" : s, "dst" : 1} for s in route[0]]
	signal = [-1] + [0] * (N - 1)

	for r in route[0]:
		checked[r - 1] = 1

	while len(to_check) > 0:
		checking = to_check.pop(0)
		src = checking["src"]
		signal[src - 1] = str(checking["dst"])
		rooms = route[src - 1]
		for r in rooms:
			if checked[r - 1] == 0:
				to_check.append({"src": r, "dst": src})
				checked[r - 1] = 1

	if signal.count(0) > 0:
		print("No")
	else:
		print("Yes")
		print("\n".join(signal[1:]))

main()

from collections import deque

N,M = map(int,input().split())
room_g = [[] for i in range(N+1)]

for i in range(M):
  a,b = map(int,input().split())
  room_g[a].append(b)
  room_g[b].append(a)
  
sign = [-1]*(N+1)
sign[0] = 0
sign[1] = 0

d = deque()
d.append(1)

while d:
  x = d.popleft()
  for i in room_g[x]:
    if sign[i] != -1:
      continue
    sign[i] = x
    d.append(i)
    
ans = sign[2:]
print("Yes")
for i in range(len(ans)):
  print(ans[i])

from collections import deque
N,M=map(int,input().split())
C=[[] for i in range(N+1)]
for i in range(M):
  A,B=sorted(list(map(int,input().split())))
  C[A].append(B)
  C[B].append(A)

d=[-1]*(N+1)
d[0]=0
d[1]=0

queue=deque([1])
while queue:
  now = queue.popleft()
  for i in C[now]:
    if d[i]!=-1:continue
    d[i]=now
    queue.append(i)

if d.count(0)>2:print('No');exit
print('Yes')
for i in range(2,N+1):
  print(d[i])

from collections import deque
N , M = map(int,input().split())
g = [[] for _ in range(N)]
for _ in range(M):
    a,b = [int(x) for x in input().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)
branch_list = [0 for i in range(N)]
def bfs(u):
    queue = deque([u])
    d = [None] *N
    d[u] = 0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] +1
                queue.append(i)
                branch_list[i] = v +1
    return d
d = bfs(0)
for i in range(1,len(branch_list)):
    if branch_list[i] == 0:
        print("No")
        break
    if i == 1:
        print("Yes")
    print(branch_list[i])

from collections import deque

n,m = map(int,input().split())
V = [[] for i in range(n+1)]

for i in range(m):
    a,b = map(int,input().split())
    V[a].append(b)
    V[b].append(a)
    
reach = [-1]*(n+1)
reach[1] = 0
q = deque([])
q.append(1)

while q:
    x = q.popleft()
    
    for y in V[x]:
        if reach[y] == -1:
            reach[y] = x
            q.append(y)

print("Yes")
for i in range(2,n+1):
    print(reach[i])

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
import numpy as np
from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = na()
edge = np.array([na() + [1] for _ in range(M)], dtype=np.int64).T
g = csr_matrix((edge[2], (edge[:2] - 1)), (N, N))
d, root = breadth_first_order(g, directed=False, return_predecessors=True, i_start = 0)
if -9999 not in d[1:]:
    print('Yes')
    for i in range(1, N):
        print(root[i] + 1)
else:
    print('No')

import copy
N, M = map(int, input().split())
res = [[] for i in range(N+5)]


for i in range(M) :
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    res[a].append(b)
    res[b].append(a)
    
pre = [-1] * N
dist = [-1] * N
d = 1
dl = []
pre[0] = 0
dist[0] = 0
dl.append(0)

while(len(dl) != 0) :
    a = dl[0]
    dl.pop(0)
    for i in res[a] :
        if(dist[i] != -1):
            continue
        dist[i] = dist[a] + 1
        pre[i] = a
        dl.append(i)
        
for i in range(N) :
    if(i == 0) :
        print("Yes")
        continue
    print(pre[i] + 1)

from collections import deque

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

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

for i in range(m):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

que = deque()
que.append(0)

visited = [0 for _ in range(n)]
visited[0] = 1
ans = [None for _ in range(n)]

print('Yes')
while len(que) > 0:
    c = que.popleft()
    for ne in graph[c]:
        if visited[ne] == 1:
            continue
        que.append(ne)
        ans[ne] = c
        # print(f'ans[{ne}] = {c}')
        visited[ne] = 1

for i in range(1, n):
    print((ans[i] + 1))


from collections import deque
n,m = list(map(int,input().split()))
#隣接リスト
print("Yes")
g = [[] for i in range(n)]
for i in range(m):
  a,b = list(map(int,input().split()))
  #0-indexにします
  g[a-1].append(b-1)
  g[b-1].append(a-1)
q = deque([])
q.append(0)
check = [0] * n
while len(q) > 0:
  e = q.popleft()
  for i in g[e]:
    if check[i] > 0:
      continue
    check[i] = e + 1
    q.append(i)
for i in range(1,n):
  print((check[i]))


from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque

n,m=nii()

tree=[[] for i in range(n)]
for i in range(m):
  a,b=nii()
  a-=1
  b-=1
  tree[a].append(b)
  tree[b].append(a)

ans=[-1 for i in range(n)]
ans[0]=1

que=deque()
que.append(0)

while que:
  x=que.popleft()
  for i in tree[x]:
    if ans[i]==-1:
      ans[i]=x
      que.append(i)

if -1 in ans:
  print('No')
else:
  print('Yes')
  for i in ans[1:]:
    print(i+1)

from collections import deque

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

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

for i in range(m):
  a, b = map(int, input().split())
  graph[a].append(b)
  graph[b].append(a)

dist = [-1] * (n + 1)
dist[0] = 0
dist[1] = 0

d = deque()
d.append(1)

while d:
  v = d.popleft()
  for i in graph[v]:
    if dist[i] != -1:
      continue
    dist[i] = v
    d.append(i)

ans = dist[2:]
print("Yes")
print(*ans, sep="\n")


import sys
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

ars = [0] * N
todo = deque([0])
done = {0}
while todo:
    p = todo.popleft()
    for np in G[p]:
        if np in done:
            continue
        todo.append(np)
        ars[np] = p + 1
        done.add(np)

if len(done) == N:
    print("Yes")
    for i in range(1, N):
        print(ars[i])
else:
    print("No")

from collections import deque

n, m = map(int, input().split())
graph = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [-1] * (n+1)
dist[0] = 0
dist[1] = 0

d = deque()
d.append(1)

#BFS実行部分
while d:
    v = d.popleft()
    for i in graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = v
        d.append(i)

if -1 in dist:
    print("No")
else:
    print("Yes")
ans = dist[2:]
print(*ans, sep="\n")


from collections import deque

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

graph = [[] for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  graph[a - 1].append(b - 1)
  graph[b - 1].append(a - 1)

ans = [-1] * (n - 1)

q = deque()
q.append(0)
used = {0}
while q:
  node = q.popleft()
  for next_node in graph[node]:
    if next_node in used:
      continue
    q.append(next_node)
    used.add(next_node)
    ans[next_node - 1] = node + 1

print('Yes')
print(*ans, sep='\n')

from collections import deque
import sys
def bfs(graph, N, start):
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())

    graph = [[] for _ in range(N)]
    for i in range(M):
        A, B = map(lambda n: int(n) - 1, input().split())
        graph[A].append(B)
        graph[B].append(A)

    visited = bfs(graph, N, 0)[1:]
    if all(visited):
        print("Yes")
        print(*visited, sep="\n")
    else:
        print("No")


main()

from collections import deque
n,m=map(int,input().split())
print('Yes')
root=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    root[a-1].append(b-1)
    root[b-1].append(a-1)
q=deque([0])
check=[0]*n
while q:
    e=q.popleft()
    for i in root[e]:
        if check[i]:
            continue
        check[i]=e+1
        q.append(i)
for i in range(1,n):
    print(check[i])

import queue

q = queue.Queue()
bool = True


def bfs():
    q.put(0)
    while not q.empty():
        now = q.get()
        for i in nodes[now]:
            if dist[i] != -1:
                continue
            dist[i] = dist[now] + 1
            q.put(i)
            ans[i] = now
    # bool = False


N, M = list(map(int, input().split()))
nodes = [[] for i in range(N)]
idxStock = []
for i in range(M):
    a, b = list(map(int, input().split()))
    nodes[a - 1].append(b - 1)
    nodes[b - 1].append(a - 1)

dist = [-1] * N
ans = [-1] * N
bfs()
if bool:
    print("Yes")
    for i in range(1, N):
        print((ans[i] + 1))
else:
    print("No")


from collections import deque

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

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

for i in range(M):
    A, B = map(int, input().split())
    graph[A].append(B)
    graph[B].append(A)

parents = [-1] * (N+1)
parents[0] = 0
parents[1] = 0

d = deque()
d.append(1)

while d:
    v = d.popleft()
    for i in graph[v]:
        if parents[i] != -1:
            continue
        parents[i] = v
        d.append(i)
ans = parents[1:]
if -1 in parents:
    print('No')
else:
    print('Yes')
    parents.pop(0)
    parents.pop(0)
    for i in parents:
        print(i)

from collections import deque

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

graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
ans = [-1] * (n - 1)
used = [0]*n
used[0] = 1
que = deque([0])
while que:
    posi = que.popleft()
    for p in graph[posi]:
        if not used[p]:
            que.append(p)
            ans[p-1] = posi+1
            used[p] = 1
print('Yes')
print(*ans, sep='\n')

from collections import deque
N,M=map(int,input().split())
haba=[[] for i in range(N+1)]
for i in range(M):
    A,B=map(int,input().split())
    haba[A].append(B)
    haba[B].append(A)
kyori=[-1]*(N+1)
kyori[0]=0
kyori[1]=0

que=deque()
que.append(1)

while que:
    kari=que.popleft()
    for i in haba[kari]:
        if kyori[i]!=-1:
            continue
        kyori[i]=kari
        que.append(i)

ans=kyori[2:]
print("Yes")
for i in range(len(ans)):
    print(ans[i])

import keyword
from collections import deque

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

G = [[] for _ in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

visited = [False] * N
par = [0] * N
visited[0] = True
d = deque(G[0])
for i in G[0]:
    visited[i] = True
    par[i] = 0
cur = 0
while d:
    cur = d.popleft()
    for i in G[cur]:
        if not visited[i]:
            visited[i] = True
            par[i] = cur
            d.append(i)

print('Yes')
for i in range(1, N):
    print((par[i] + 1))


from collections import deque

N, M = [int(x) for x in input().split()]

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

for i in range(M):
    A, B = [int(x) for x in input().split()]
    conn[A].append(B)
    conn[B].append(A)

q = deque([1])
signpost = [0] * (N + 1)

while q:
    v = q.popleft()
    for w in conn[v]:
        if signpost[w] == 0:
            signpost[w] = v
            q.append(w)

print('Yes')
for i in range(2, N + 1):
    print(signpost[i])

#ダイクストラ法
import heapq
def dijkstra(s):
    p=[x for x in range(n)]#親の記憶
    hq = [(0, s)]
    heapq.heapify(hq) # リストを優先度付きキューに変換
    cost = [float('inf')] * n # 行ったことのないところはinf
    cost[s] = 0 # 開始地点は0
    while hq:
        c, v = heapq.heappop(hq)
        if c > cost[v]: # コストが現在のコストよりも高ければスルー
            continue
        for d, u in e[v]:
            tmp = d + cost[v]
            if tmp < cost[u]:
                cost[u] = tmp
                p[u]=v
                heapq.heappush(hq, (tmp, u))
    return p

n,m = list(map(int,input().split()))
#重み付き有向グラフの隣接リストe(重み=1)
e = [[] for _ in range(n)]
t=1
for _ in range(m):
    a,b= list(map(int,input().split()))
    a,b = a-1, b-1
    e[a].append((t, b))
    e[b].append((t, a))

ans = dijkstra(0)
print('Yes')
for i in range(1,n):
  print((ans[i]+1))


from collections import deque

N,M=map(int,input().split())
G=[[] for _ in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  G[a].append(b)
  G[b].append(a)

ans=[0]*(N+1)
d=deque([1])
while d:
  c=d.popleft()
  for g in G[c]:
    if not ans[g]:
      d.append(g)
      ans[g]=c

print('Yes')
for i in range(2, N+1):
  print(ans[i])

from collections import deque

n, m = map(int, input().split())
c = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    c[a].append(b)
    c[b].append(a)

if len(c[0]) == 0:
    print('No')
    return

l = [0]*n
l[0] = 1
q = deque()
for i in c[0]:
    q.append(i)
    l[i] = 1
while q:
    p = q.pop()
    for i in c[p]:
        if l[i] == 0:
            l[i] = p+1
            q.appendleft(i)

print('Yes')
for i in range(1, n):
    print(l[i])

import sys
from sys import stdin
def I():
    return stdin.readline().rstrip()
def MI():
    return map(int,stdin.readline().rstrip().split())
def LI():
    return list(map(int,stdin.readline().rstrip().split()))
#main part
from collections import deque
 
n, m =MI()
 
ans = [-1 for _ in range(n+1)]


ans[0] = 0
ans[1] = 0
 
V = [[] for _ in range(n+1)]
 
for _ in range(m):
    x, y = MI()
    V[x].append(y)
    V[y].append(x)
 
d = deque([1])
 
while d:
    l = d.popleft()
    for v in V[l]:
        if ans[v] != -1:
            continue
        ans[v] = l
        d.append(v)
        
 
    
if ans.count(-1) > 0:
    print('No')
else :
    print('Yes')
    for i in ans[2:]:
        print(i)

from collections import deque

N, M = map(int, input().split())
dist = [-1] * N
# 初期化を忘れないように！スタート位置に既訪問フラグを立てる。ループ内では立てないので
dist[0] = 0
prv = [0] * N
G = [[] for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

d = deque()
d.append(0)

while d:
    now = d.popleft()
    for nv in G[now]:
        if dist[nv] == -1:
            # dist[nv]: 最短経路の長さを保持。この問題では不要なのでフラグとして１を入れるだけでも事足りる。
            dist[nv] = dist[now] + 1
            prv[nv] = now
            d.append(nv)

print("Yes")
for p in prv[1:]:
    print(p + 1)

from collections import deque
N,M = map(int,input().split())

graph = [[] for _ in range(N)]
flag = [0] * N

for i in range(M):
  A, B = map(int,input().split())
  A -= 1
  B -= 1
  graph[A].append(B)
  graph[B].append(A)
  
D = deque()
D.append(0)
visited = [False] * N
visited[0] = True

while D:
  v = D.popleft()
  for nv in graph[v]:
    if visited[nv] == True:
      continue
    visited[nv] = True
    flag[nv] = v
    D.append(nv)
    
print("Yes")
for i in range(1,N):
  print(flag[i] + 1)

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

neighbors = {}
for _ in range(m):
  a, b = list(map(int, input().split()))
  if a not in list(neighbors.keys()):
    neighbors.update({a:set()})
  if b not in neighbors[a]:
    neighbors[a].add(b)
  if b not in list(neighbors.keys()):
    neighbors.update({b:set()})
  if a not in neighbors[b]:
    neighbors[b].add(a)
#print(neighbors)
lst = [0] * (n - 1) #部屋１を除く、すべての部屋の通り方を調べる、「通っていない」を0として定義
visited = set() #一度訪れた部屋は再度探索する必要はないので、それを省くための集合
queue = [[0, set([1])]]
while queue:
  #print(queue)
  pre_room, rooms = queue.pop(0) #左が今いる部屋、右が次に進む部屋
  #print(pre_room, rooms)
  for room in rooms:
    if room in visited:
      continue
    if lst[room - 2] == 0 and room != 1: #次に進む部屋が通っていないかどうか（と今いる部屋が１ではないこと）の確認
      lst[room - 2] = pre_room #部屋2の場合、lstのindexは0に相当するので-2する必要がある
    visited.add(room) #今いる部屋を訪れたので、集合に入れる
    next_rooms = set() #次に進む部屋を探索する
    for nei in neighbors[room]:
      next_rooms.add(nei)
    next_rooms = [room, next_rooms]
    queue.append(next_rooms)
if 0 in lst:
  print('No')
else:
  print('Yes')
  for i in range(n - 1):
    print((lst[i]))


n,m = map(int,input().split())
AB = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    AB[a-1].append(b-1)
    AB[b-1].append(a-1)

visited = set()
ans = [0]*n
stack = [0]
for i in stack:
    # このへんあやしい
    for j in AB[i]:
        if j in visited:
            continue
        visited.add(j)
        ans[j] = i+1
        stack.append(j)
    # このへんまで
for i in ans[1:]:
    if i==0:
        print('No')
        return
print('Yes')
for i in ans[1:]:
    print(i)

# 参考にした提出:https://atcoder.jp/contests/abc168/submissions/16604668 #
from collections import deque
n,m = map(int,input().split())
l = [[] for i in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    l[a].append(b)
    l[b].append(a)
d = [-1] * (n+1)
d[0],d[1] = 0,0
queue = deque()
queue.append(1)
while queue:
    x = queue.popleft()
    for i in l[x]:
        if d[i] == -1:
            d[i] = x
            queue.append(i)
if -1 in d:
    print('No')
else:
    print('Yes')
    for i in d[2:]:
        print(i)

from collections import deque

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

connected = [set() for i in range(n+1)]

for i in range(m):
  a,b = map(int, input().split())
  connected[a].add(b)
  connected[b].add(a)
  
def bfs(x):
  queue = deque([x])
  d = [None] * (n+1)
  d[x] = 0
  while queue:
    v = queue.popleft()
    for i in connected[v]:
      if d[i] is None:
        d[i] = v
        queue.append(i)
  return d

print('Yes')
ans = bfs(1)[2:]

for i in ans:
  print(i)

import queue
n,m=list(map(int,input().split()))
l=[[] for i in range(n)]

for _ in range(m):
    tempa,tempb=list(map(int,input().split()))
    tempa-=1
    tempb-=1
    l[tempa].append(tempb)
    l[tempb].append(tempa)
que=queue.Queue()
dist=[-1]*n

dist[0]=0
que.put(0)
ans=[0]*n

while not que.empty():
    v=que.get()

    for nv in l[v]:
        if dist[nv]!=-1:
            continue
        dist[nv]=dist[v]+1
        que.put(nv)
        ans[nv]=v
if -1 in dist:
    print('No')
else:
    print('Yes')
    for i in range(1,n):
        print((ans[i]+1))


from collections import defaultdict, deque

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

for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    path[A].append(B)
    path[B].append(A)

prev = [0] * N
dist = [0] * N
q = deque([0])

while (len(q) > 0):
    a = q.popleft()
    for b in path[a]:
        if dist[b] != 0:continue
        q.append(b)
        prev[b] = a
        dist[b] = dist[a] + 1

print('Yes')

for a in prev[1:]:
    a += 1
    print(a)

from collections import deque
N,M=map(int,input().split())
A=[0]*M;B=[0]*M
C=[[] for i in range(N+1)]

for i in range(M):
  A[i],B[i]=sorted(list(map(int,input().split())))
  C[A[i]].append(B[i])
  C[B[i]].append(A[i])

d=[-1]*(N+1)
d[0]=0
d[1]=0

queue=deque()
queue.append(1)

while queue:
  now = queue.popleft()
  for i in C[now]:
    if d[i]!=-1:continue
    d[i]=d[now]+1
    queue.append(i)
#print(d)
E=[0]*(N+1)
for i in range(M):
#  print(d[A[i]],d[B[i]])
  if d[B[i]]-d[A[i]]==1 and E[B[i]]==0:E[B[i]]=A[i]
  elif d[A[i]]-d[B[i]]==1 and E[A[i]]==0:E[A[i]]=B[i]
if E.count(0)>2:print('No');exit
print('Yes')
for i in range(2,N+1):
  print(E[i])

from collections import deque
n,m = list(map(int,input().split()))
load = [list(map(int,input().split())) for _ in range(m)]
goal = [[] for _ in range(n)]
for i in load:
    goal[i[0]-1].append(i[1]-1)
    goal[i[1]-1].append(i[0]-1)

q = deque([0])
ans = [-1 for _ in range(n)]
ans[0] = 0
while q:
    check = q.popleft()
    for j in goal[check]:
        if ans[j] == -1:
            ans[j] = check+1
            q.append(j)
if -1 in ans:
    print("No")
else:
    print("Yes")
    for p in range(1,n):
        print((ans[p]))


from collections import deque

print("Yes")

N, M = map(int, input().split())
net = [[] for _ in range(N+1)]
vect = [0]*(N+1)

for _ in range(M):
	A, B = map(int, input().split())
	net[A].append(B)
	net[B].append(A)

q = deque()
q.append(1)

while len(q)>0:
	t = q.popleft()
	for i in net[t]:
		if t != i and vect[i] == 0:
			vect[i] = t
			q.append(i)

for i in range(2, N+1):
	print(vect[i])

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

dist = [-1] * (N+1)
dist[1] = 0
connection = [[] for _ in range(N+1)]
ans = [-1] * (N+1)

for quel in range(M):
    a, b = map(int, input().split())
    connection[a].append(b)
    connection[b].append(a)

que = []
que.append(1)

while que:
    v = que.pop(0)

    for i in connection[v]:
        if dist[i] != -1:continue

        dist[i] = dist[v] + 1
        que.append(i)
        ans[i] = v

#print(dist)
print('Yes')
for j in range(2, N+1):
    print(ans[j])

from collections import deque

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

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

for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

#  print(graph)

mark = [-1]*(n+1)
mark[0] = 0
mark[1] = 0

d = deque()
d.append(1)

while d:
    v = d.popleft()
    for i in graph[v]:
        if mark[i] != -1:
            continue
        mark[i] = v
        d.append(i)
if mark.count(-1) > 0:
    print("No")
else:
    print("Yes")
    ans = mark[2:]
    print(*ans, sep="\n")

def abc168d_double_dots():
    n, m = map(int, input().split())
    path_dict = {}
    for _ in range(m):
        a, b = map(int, input().split())
        if b not in path_dict.keys():
            path_dict[b] = [a]
        else:
            path_dict[b].append(a)
        a, b = b, a
        if b not in path_dict.keys():
            path_dict[b] = [a]
        else:
            path_dict[b].append(a)

    q = [1]
    cnt = 0
    ans = [0] * n
    ans[0] = 1
    while len(q) != 0:
        no = q.pop(0)
        for next_room in path_dict[no]:
            if ans[next_room - 1] == 0:
                ans[next_room - 1] = no
                q.append(next_room)
                cnt += 1

    if cnt != n-1:
        print('No')
        return
    print('Yes')
    for a in ans[1:]:
        print(a)


abc168d_double_dots()

# 参考にした提出:https://atcoder.jp/contests/abc168/submissions/16604668 #
from collections import deque
n,m = map(int,input().split())
l = [[] for i in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    l[a].append(b)
    l[b].append(a)
d = [-1] * (n+1)
d[0],d[1] = 0,0
queue = deque()
queue.append(1)
while queue:
    x = queue.popleft()
    for i in l[x]:
        if d[i] == -1:
            d[i] = x
            queue.append(i)
print('Yes')
for i in d[2:]:
    print(i)

from collections import deque
N,M=map(int,input().split())
A=[0]*M;B=[0]*M
C=[[] for i in range(N+1)]

for i in range(M):
  A[i],B[i]=sorted(list(map(int,input().split())))
  C[A[i]].append(B[i])
  C[B[i]].append(A[i])

d=[-1]*(N+1)
d[0]=0
d[1]=0

queue=deque([1])
while queue:
  now = queue.popleft()
  for i in C[now]:
    if d[i]!=-1:continue
    if d[i]==-1:d[i]=now
#    d[i]=d[now]+1
    queue.append(i)
#print(d)
#return
#E=[0]*(N+1)
#for i in range(M):
#  if d[B[i]]-d[A[i]]==1 and E[B[i]]==0:E[B[i]]=A[i]
#  elif d[A[i]]-d[B[i]]==1 and E[A[i]]==0:E[A[i]]=B[i]
if d.count(0)>2:print('No');exit
print('Yes')
for i in range(2,N+1):
  print(d[i])

#!/usr/bin/env python3
import sys
from itertools import chain

# from itertools import combinations as comb
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np

YES = "Yes"  # type: str


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    routes = [set() for _ in range(N)]
    marks = [None for _ in range(N)]
    for a, b in zip(A, B):
        a = a - 1
        b = b - 1
        routes[a].add(b)
        routes[b].add(a)

    marks[0] = -1
    cur_rooms = [0]
    count = 1
    while count < N:
        new_cur_rooms = []
        for cur_room in cur_rooms:
            next_rooms = list(routes[cur_room])
            for next_room in next_rooms:
                if marks[next_room] is None:
                    marks[next_room] = cur_room
                    new_cur_rooms.append(next_room)
                    count += 1
        cur_rooms = new_cur_rooms

    answer = "Yes\n" + "\n".join((str(n + 1) for n in marks[1:]))

    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, M, A, B = map(int, line.split())
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    answer = solve(N, M, A, B)
    print(answer)


def __starting_point():
    main()

__starting_point()

# import itertools
# import math
import sys
sys.setrecursionlimit(500*500)
# import numpy as np
from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# A_B = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# edges = [list(map(int,input().split())) for _ in range(M)]
# tree = [[] for _ in range(N + 1)]

# for edge in edges:
#     tree[edge[0]].append([edge[1], edge[2]])
#     tree[edge[1]].append([edge[0], edge[2]])

# depth = [-1] * (N + 1)
# depth[1] = 0

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

tree = [[] for _ in range(N + 1)]
edges = [list(map(int,input().split())) for _ in range(M)]

for edge in edges:
    tree[edge[0]].append(edge[1])
    tree[edge[1]].append(edge[0])

depth = [-1] * (N + 1)
depth[1] = 0

d = deque()
d.append(1)

ans = [0] * (N + 1)
while d:
 v = d.popleft()
 for i in tree[v]:
   if depth[i] != -1:
     continue
   depth[i] = depth[v] + 1
   ans[i] = v
   d.append(i)

# ans = depth[2:]
print('Yes')
print(*ans[2:], sep="\n")

from collections import deque

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

graph = [[] for _ in range(n+1)]
dist = [0] * (n+1)
visited = [0] * (n+1)


for _ in range(m):
    a,b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

root = 1
visited[root] = 1
d  = deque([root])

while d:
    v = d.popleft()
    for i in graph[v]:
        if visited[i]:
            continue
        visited[i] = 1
        dist[i] = v
        d.append(i)

print('Yes')
ans = dist[2:]
print(*ans, sep="\n")

from collections import deque

n, m = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    a[x - 1].append(y - 1)
    a[y - 1].append(x - 1)
c = [0] * n
que = deque([])
que.append(0)
while len(que) > 0:
    e = que.popleft()
    for i in a[e]:
        if c[i] > 0:
            continue
        c[i] = e + 1
        que.append(i)
print("Yes")
for i in range(1, n):
    print(c[i])

from collections import deque

n, m = map(int,input().split())
g = [[] for _ in range(n+1)]
for i in range(m):
  a, b = map(int,input().split())
  g[a].append(b)
  g[b].append(a)
  
yet = [-1 for _ in range(n+1)]
yet[0] = 0
yet[1] = 1

d = deque([1])

while d:
  v = d.popleft()
  for i in g[v]:
    if yet[i] == -1:
      yet[i] = v
      d.append(i)
      
ans = yet[2:]
print("Yes")
print(*ans, sep="\n")

N,M=map(int,input().split())
l=[[] for i in range(N)]
for i in range(M):
   a,b=map(int,input().split())
   a-=1;b-=1
   l[a].append(b)
   l[b].append(a)
visited=[-1]*N
visited[0]=1
from collections import deque
que=deque([0])
while que:
   node=que.popleft()
   for i in l[node]:
      if visited[i]==-1:
         visited[i]=node+1
         que.append(i)
if -1 in visited:
   print("No")
else:
   print("Yes")
   for i in range(1,N):
      print(visited[i])

from collections import deque

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

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

for i in range(m):
    a,b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

# dist = [-1]*(n+1)
# dist[0] = 0
# dist[1] = 0
mark = [-1]*(n+1)
mark[0] - 0
mark[1] = 0


d = deque()
d.append(1)

while d:
    v = d.popleft()
    for i in graph[v]:
        if mark[i] != -1:
        # if dist[i] != -1:
            continue
        mark[i] = v
        # dist[i] = dist[v] + 1
        d.append(i)

if '-1' in mark:
    print('No')
else:
    print('Yes')
    print(*mark[2:], sep='\n')