AtCoder Beginner Contest 168 - .. (Double Dots)

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.

Source: atcoder | Difficulty: MEDIUM


Solutions:
from collections import deque
(n, m) = map(int, input().split())
V = [[] for _ in range(n + 1)]
for _ in range(m):
	(a, b) = map(int, input().split())
	V[a].append(b)
	V[b].append(a)
ans = [-1] * (n + 1)
q = deque()
q.append(1)
while q:
	p = q.popleft()
	for c in V[p]:
		if c > 1 and ans[c] < 0:
			ans[c] = p
			q.append(c)
print('Yes')
for i in range(2, n + 1):
	print(ans[i])


(N, M) = map(int, input().split())
route = [[] for _ in range(N)]
sign = [0] * N
for i in range(M):
	(a, b) = map(int, input().split())
	route[a - 1].append(b - 1)
	route[b - 1].append(a - 1)
marked = {0}
q = [0]
for i in q:
	for j in route[i]:
		if j in marked:
			continue
		q.append(j)
		marked.add(j)
		sign[j] = i + 1
print('Yes')
[print(i) for i in sign[1:]]


from collections import deque
INF = 1000000000

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()


(N, M) = map(int, input().split())
e = [[] for _ in range(N)]
for i in range(M):
	(a, b) = map(int, input().split())
	e[a - 1].append(b - 1)
	e[b - 1].append(a - 1)
visited = [0] * N
visited[0] = 1
que = [0]
while que:
	x = que.pop(0)
	for i in e[x]:
		if visited[i] == 0:
			visited[i] = x + 1
			que.append(i)
print('Yes')
print(*visited[1:], 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):
	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
(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)
ans = [-1] * (n + 1)
ans[0] = 0
ans[1] = 0
d = deque()
d.append(1)
while d:
	v = d.popleft()
	for i in graph[v]:
		if ans[i] != -1:
			continue
		ans[i] = v
		d.append(i)
ans = ans[2:]
print('Yes')
print(*ans, sep='\n')


f = lambda : map(int, input().split())
(n, m) = f()
g = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = f()
	g[a - 1] += [b - 1]
	g[b - 1] += [a - 1]
p = [0] * n
from collections import *
q = deque([0])
while q:
	v = q.popleft()
	for c in g[v]:
		if p[c] < 1:
			p[c] = v + 1
			q.append(c)
if 0 in p:
	print('No')
else:
	print('Yes', *p[1:], sep='\n')


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) = 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


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ans = [-1 for _ in range(n)]
ans[0] = 0
tree = [[] for _ in range(n)]
for (a, b) in ab:
	tree[a - 1].append(b - 1)
	tree[b - 1].append(a - 1)
visited = {0}
q = [0]
for i in q:
	for j in tree[i]:
		if ans[j] < 0:
			q.append(j)
			ans[j] = i + 1
print('Yes')
for i in ans[1:]:
	print(i)


(n, m) = map(int, input().split())
l = [-1] * n
d = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = map(int, input().split())
	d[a - 1].append(b - 1)
	d[b - 1].append(a - 1)
from collections import deque
q = deque()
q.append(0)
while q:
	now = q.popleft()
	for x in d[now]:
		if l[x] == -1:
			l[x] = now
			q.append(x)
if -1 in l:
	print('No')
else:
	print('Yes')
	for i in l[1:]:
		print(i + 1)


from collections import deque

def main():
	(N, M, *AB) = map(int, open(0).read().split())
	to = [[] for _ in range(N)]
	for (a, b) in zip(*[iter(AB)] * 2):
		to[a - 1].append(b - 1)
		to[b - 1].append(a - 1)
	q = deque([0])
	r = [None] * N
	while q:
		x = q.popleft()
		for i in to[x]:
			if not r[i]:
				q.append(i)
				r[i] = x + 1
	print('Yes', *r[1:], sep='\n')
main()


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])


import sys
from collections import deque
input = sys.stdin.readline
(n, m) = map(int, input().split())
l = [[] for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	l[a - 1].append(b - 1)
	l[b - 1].append(a - 1)
ans = [-1] * n
ans[0] = 0
print('Yes')
d = deque([0])
while d:
	now = d.pop()
	for x in l[now]:
		if ans[x] < 0:
			ans[x] = now
			d.appendleft(x)
for i in range(1, n):
	print(ans[i] + 1)


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])


(N, M) = map(int, input().split())
box = [[] for i in range(N)]
for i in range(M):
	(a, b) = map(int, input().split())
	box[a - 1].append(b - 1)
	box[b - 1].append(a - 1)
ans = [None] * N
ans[0] = 0
que = [0]
while len(que) > 0:
	index = que.pop(0)
	for x in box[index]:
		if ans[x] == None:
			ans[x] = index + 1
			que.append(x)
print('Yes')
for i in range(1, N):
	print(ans[i])


from collections import deque
(N, M) = map(int, input().split())
G = [[] for i in range(N)]
for _ in range(M):
	(A, B) = map(int, input().split())
	G[A - 1].append(B - 1)
	G[B - 1].append(A - 1)
T = [-1] * N
que = deque()
que.append(0)
while que:
	v = que.popleft()
	for e in G[v]:
		if T[e] == -1:
			T[e] = v + 1
			que.append(e)
print('Yes')
print(*T[1:], sep='\n')


(N, M) = map(int, input().split())
V = [[] for _ in range(N)]
for _ in range(M):
	(a, b) = map(int, input().split())
	a = a - 1
	b = b - 1
	V[a].append(b)
	V[b].append(a)
from collections import deque
q = deque([0])
ans = [-1] * N
ans[0] = 0
while q:
	v = q.popleft()
	for nv in V[v]:
		if ans[nv] == -1:
			ans[nv] = v + 1
			q.append(nv)
print('Yes')
print(*ans[1:], sep='\n')


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(' '))
ar = [[] for i in range(n)]
br = [0 for i in range(n)]
for i in range(m):
	(x, y) = map(int, input().split(' '))
	ar[x - 1].append(y - 1)
	ar[y - 1].append(x - 1)
cr = [0]
dr = []
for r in cr:
	for i in ar[r]:
		if br[i] == 0:
			br[i] = r + 1
			cr.append(i)
print('Yes')
for i in range(1, n):
	print(br[i])


(N, M) = map(int, input().split())
g = [[] for _ in range(N + 1)]
for _ in range(M):
	(a, b) = map(int, input().split())
	g[a].append(b)
	g[b].append(a)
from collections import deque
queue = deque([1])
d = [None] * (N + 1)
d[1] = None
while queue:
	now = queue.popleft()
	for i in g[now]:
		if d[i] is None:
			d[i] = now
			queue.append(i)
print('Yes')
for i in range(2, N + 1):
	print(d[i])


from collections import deque
(N, M) = map(int, input().split())
to = [[] for _ in range(N)]
for _ in range(M):
	(a, b) = map(int, input().split())
	to[a - 1].append(b - 1)
	to[b - 1].append(a - 1)
q = deque([0])
r = deque([None] * N)
r[0] = 0
while q:
	x = q.popleft()
	for i in to[x]:
		if r[i] is None:
			q.append(i)
			r[i] = x + 1
print('Yes')
r.popleft()
for i in range(N - 1):
	print(r.popleft())


(N, M) = list(map(int, input().split()))
g = [[] for i in range(N + 1)]
for i in range(M):
	(a, b) = list(map(int, input().split()))
	g[a].append(b)
	g[b].append(a)
from collections import deque
queue = deque([1])
d = [None] * (N + 1)
while queue:
	v = queue.popleft()
	for i in g[v]:
		if d[i] is None:
			d[i] = v
			queue.append(i)
print('Yes')
print(*d[2:], sep='\n')


(n, m) = map(int, input().split())
G = [[] for _ in range(1 + n)]
for i in range(m):
	(a, b) = map(int, input().split())
	G[a].append(b)
	G[b].append(a)
from collections import deque
vis = [0] * (1 + n)
q = deque([1])
while q:
	now = q.popleft()
	for next in G[now]:
		if vis[next] == 0:
			vis[next] = now
			q.append(next)
print('Yes')
for i in range(2, n + 1):
	print(vis[i])


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
ans = [0] * n
edge = [[] for _ in range(n)]
for (a, b) in ab:
	edge[a - 1].append(b - 1)
	edge[b - 1].append(a - 1)
visited = {0}
stack = [0]
for i in stack:
	for j in edge[i]:
		if j in visited:
			continue
		stack.append(j)
		visited.add(j)
		ans[j] = i + 1
print('Yes')
print(*ans[1:])


(n, m) = map(int, input().split())
c = [[] for i in range(n)]
d = [0]
e = [-1] * n
for i in range(m):
	(a, b) = map(int, input().split())
	c[a - 1].append(b - 1)
	c[b - 1].append(a - 1)
while d:
	f = d.pop(0)
	for i in c[f]:
		if e[i] == -1:
			d.append(i)
			e[i] = f
print('Yes')
for i in range(n - 1):
	print(e[i + 1] + 1)


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())
ab = [list(map(int, input().split())) for _ in range(m)]
path = [[] for _ in range(n + 1)]
for (a, b) in ab:
	path[a].append(b)
	path[b].append(a)
q = deque([1])
ans = [0] * (n + 1)
while q:
	v = q.popleft()
	for w in path[v]:
		if ans[w] == 0:
			ans[w] = v
			q.append(w)
print('Yes')
print(*ans[2:], sep='\n')


import queue
I = lambda : map(int, input().split())
(N, M) = I()
ls = [[] for _ in range(N + 1)]
for _ in [0] * M:
	(A, B) = I()
	ls[A] += [B]
	ls[B] += [A]
q = queue.Queue()
v = [-1] * (N + 1)
v[0] = v[1] = 0
q.put(1)
while not q.empty():
	top = q.get()
	for l in ls[top]:
		if v[l] < 0:
			v[l] = top
			q.put(l)
if -1 in v:
	print('No')
else:
	print('Yes')
	[print(k) for k in v[2:]]


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)


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
(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())
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)
q = deque([0])
pre = [-1 for _ in range(n)]
while q:
	v = q.popleft()
	for t in g[v]:
		if pre[t] == -1:
			pre[t] = v
			q.append(t)
print('Yes')
for i in range(1, n):
	print(pre[i] + 1)


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()))
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)


(n, m) = map(int, input().split())
s = [[] for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	s[a - 1].append(b - 1)
	s[b - 1].append(a - 1)
t = [-1] * n
q = [0]
while q:
	p = []
	for j in q:
		for i in s[j]:
			if i != j and t[i] == -1:
				p.append(i)
				t[i] = j
	q = p[:]
print('Yes')
for i in t[1:]:
	print(i + 1)


(N, M) = map(int, input().split())
node = [[] for _ in range(N)]
for _ in range(M):
	(x, y) = map(int, input().split())
	node[x - 1].append(y - 1)
	node[y - 1].append(x - 1)
ct = [-1] * N
i = 0
stack = []
ct[0] = 0
stack.append(0)
while len(stack) != 0:
	v = stack.pop(0)
	for e in node[v]:
		if ct[e] == -1:
			ct[e] = v
			stack.append(e)
print('Yes')
for i in range(1, N):
	print(ct[i] + 1)


import collections
(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)
q = collections.deque()
q.append(1)
visit = [-1] * (n + 1)
visit[1] = 1
ans = [0] * (n + 1)
while q:
	v = q.popleft()
	for i in g[v]:
		if visit[i] == -1:
			ans[i] = v
			visit[i] = 1
			q.append(i)
print('Yes')
for i in range(2, n + 1):
	print(ans[i])


from collections import deque
(n, m) = map(int, input().split())
G = [[] for i 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([0])
V = [0] * n
V[0] = 1
P = [0] * n
while len(D) > 0:
	x = D[0]
	D.popleft()
	for i in range(len(G[x])):
		if V[G[x][i]] == 0:
			V[G[x][i]] = 1
			P[G[x][i]] = x + 1
			D.append(G[x][i])
print('Yes')
for i in range(1, n):
	print(P[i])


from collections import deque
(N, M) = map(int, input().split())
ab = [[] for i in range(N + 1)]
for i in range(M):
	(a, b) = map(int, input().split())
	ab[a].append(b)
	ab[b].append(a)
ans = [-1] * (N + 1)
que = deque([1])
while que:
	q = que.popleft()
	for i in ab[q]:
		if ans[i] == -1:
			que.append(i)
			ans[i] = q
print('Yes')
for i in range(2, N + 1):
	print(ans[i])


import queue
(n, m) = map(int, input().split())
to = [[] for i in range(n + 1)]
pre = [-1] * (n + 1)
for i in range(m):
	(a, b) = map(int, input().split())
	to[a].append(b)
	to[b].append(a)
q = queue.Queue()
q.put((1, 0))
while not q.empty():
	(x, p) = q.get()
	if pre[x] != -1:
		continue
	pre[x] = p
	for i in to[x]:
		if pre[i] == -1:
			q.put((i, x))
print('Yes')
for p in pre[2:]:
	print(p)


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) = 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
print('Yes')
for i in range(1, n):
	print(updated_from[i] + 1)


from collections import deque
(n, m) = map(int, input().split())
u = [[] for _ in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	u[a].append(b)
	u[b].append(a)
q = deque([0])
ans = [-1] * n
count = 0
while len(q):
	p = q.popleft()
	for x in u[p]:
		if ans[x] == -1:
			ans[x] = p + 1
			q.append(x)
ans[0] = 'Yes'
for i in range(n):
	print(ans[i])


(n, m) = map(int, input().split())
l = [[] for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	l[a - 1].append(b)
	l[b - 1].append(a)
ans = [-1] * n
ans[0] = 0
x = [1]
y = []
count = 1
while x != []:
	for i in x:
		for j in l[i - 1]:
			if ans[j - 1] == -1:
				ans[j - 1] = i
				y.append(j)
				count += 1
	x = y
	y = []
print('Yes')
for i in range(1, n):
	print(ans[i])


(N, M) = map(int, input().split())
X = [[] for i in range(N + 1)]
for i in range(M):
	(a, b) = map(int, input().split())
	X[a] += [b]
	X[b] += [a]
ans = [0] * (N + 1)
ans[1] = 1
from collections import deque
que = deque([1])
while que:
	q = que.popleft()
	for i in X[q]:
		if ans[i] == 0:
			ans[i] = q
			que.append(i)
print('Yes')
print(*ans[2:], sep='\n')


(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
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('Yes')
for i in range(1, N):
	print(pre[i])


((n, m), *e) = [[*map(int, t.split())] for t in open(0)]
t = [[] for _ in range(n + 1)]
for (a, b) in e:
	t[a] += [b]
	t[b] += [a]
q = [1]
a = [0] * -~n
while q:
	q = [a[j] == 0 and (a.__setitem__(j, i) or j) for i in q for j in t[i]]
print('Yes', *a[2:])


(n, m) = map(int, input().split())
g = [[] for x in range(n)]
for c in range(m):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
ans_list = [-1] * n
queue = [0]
while queue:
	qi = queue.pop(0)
	for gi in g[qi]:
		if ans_list[gi] == -1:
			queue.append(gi)
			ans_list[gi] = qi
print('Yes')
for ans in ans_list[1:]:
	print(ans + 1)


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


from collections import deque
(N, M) = map(int, input().split())
edge = [map(int, input().split()) for _ in range(M)]
g = [[] for _ in range(N + 1)]
for (a, b) in edge:
	g[a].append(b)
	g[b].append(a)
ans = [-1] * (N + 1)
q = deque([1])
while q:
	i = q.popleft()
	for j in g[i]:
		if ans[j] == -1:
			ans[j] = i
			q.append(j)
print('Yes')
for i in ans[2:]:
	print(i)


from collections import deque
(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
g = [[] for _ in range(N + 1)]
for (a, b) in AB:
	g[a].append(b)
	g[b].append(a)
d = deque([1])
l = [0] * (N + 1)
while d:
	r = d.popleft()
	for s in g[r]:
		if l[s] == 0:
			d.append(s)
			l[s] = r
print('Yes', *l[2:], sep='\n')


def main():
	(N, M) = map(int, input().split())
	r = [[] for i in range(N)]
	for i in range(M):
		(a, b) = map(int, input().split())
		r[a - 1].append(b - 1)
		r[b - 1].append(a - 1)
	p = [-1] * N
	q = [0]
	while q:
		i = q.pop(0)
		for j in r[i]:
			if p[j] == -1:
				p[j] = i
				q.append(j)
	print('Yes')
	for i in range(1, N):
		print(p[i] + 1)
main()


(N, M) = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(M)]
es = [[] for _ in range(N)]
for (a, b) in AB:
	es[a - 1].append(b - 1)
	es[b - 1].append(a - 1)
ans = [-1] * N
ans[0] = 0
import queue
que = queue.Queue()
que.put(0)
while que.qsize():
	s = que.get()
	for v in es[s]:
		if ans[v] == -1:
			ans[v] = s + 1
			que.put(v)
print('Yes')
print(*ans[1:], sep='\n')


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) = map(int, input().split())
paths = [[] for _ in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	paths[b].append(a)
	paths[a].append(b)
q = deque()
q.append(1)
l = [-1] * (n + 1)
l[1] = 0
while q:
	v = q.popleft()
	for i in paths[v]:
		if l[i] == -1:
			l[i] = v
			q.append(i)
print('Yes')
for i in l[2:]:
	print(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):
		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):
		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):
		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())
G = [[] for _ in [0] * (N + 1)]
for _ in [0] * M:
	(a, b) = map(int, input().split())
	G[a] += [b]
	G[b] += [a]
F = [-1] * (N + 1)
q = deque()
q.append((1, 1))
while q:
	(room, par) = q.popleft()
	if F[room] > 0:
		continue
	F[room] = par
	for nroom in G[room]:
		q.append((nroom, room))
print('Yes')
print(*F[2:], sep='\n')


from collections import deque
(n, m) = map(int, input().split())
r = [[0] for i in range(n + 1)]
num = {0: 0, 1: 1}
e = deque([])
for i in range(m):
	(a, b) = map(int, input().split())
	r[a].append(b)
	r[b].append(a)
e.append(1)
while len(e) > 0:
	x = e.popleft()
	for y in r[x]:
		if y not in num:
			num[y] = x
			e.append(y)
print('Yes')
for i in range(2, n + 1):
	print(num[i])


(n, m) = map(int, input().split())
r = [[] for x in range(n)]
for c in range(m):
	(a, b) = map(int, input().split())
	r[a - 1].append(b - 1)
	r[b - 1].append(a - 1)
s = [-1] * n
u = [0]
v = []
k = 1
for c in range(10 ** 5):
	for d in u:
		for e in r[d]:
			if s[e] == -1:
				s[e] = d
				k += 1
				v.append(e)
	if k > n - 1:
		break
	u = v
print('Yes')
for c in range(n - 1):
	print(s[c + 1] + 1)


import queue
(N, M) = map(int, input().split())
D = [[] for i in range(N)]
for i in range(M):
	(a, b) = map(int, input().split())
	D[a - 1].append(b)
	D[b - 1].append(a)
print('Yes')
dist = [0 for i in range(N)]
prev = [0 for i in range(N)]
prev[0] == 1
q = queue.Queue()
q.put(1)
while not q.empty():
	t = q.get()
	for i in D[t - 1]:
		if prev[i - 1] == 0:
			prev[i - 1] = t
			q.put(i)
for i in prev[1:]:
	print(i)


import queue
import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
x = [[] for _ in range(n + 1)]
ans = [0] * (n + 1)
for _ in range(m):
	(ai, bi) = map(int, input().split())
	x[ai].append(bi)
	x[bi].append(ai)
q = queue.Queue()
q.put(1)
while not q.empty():
	i = q.get()
	for nx in x[i]:
		if ans[nx] == 0:
			ans[nx] = i
			q.put(nx)
print('Yes')
for i in range(2, n + 1):
	print(ans[i])


from collections import deque
(n, m) = map(int, input().split())
x = [[] for i in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	x[a] += [b]
	x[b] += [a]
ans = [0] * (n + 1)
ans[1] = 1
que = deque([1])
while que:
	q = que.popleft()
	for i in x[q]:
		if ans[i] == 0:
			ans[i] = q
			que.append(i)
print('Yes')
print(*ans[2:], sep='\n')


(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])


import queue
(n, m) = map(int, input().split())
G = [[] for _ in range(n)]
for index1 in range(m):
	(a, b) = map(int, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
dist = [-1] * n
dist[0] = 0
q = queue.Queue()
q.put(0)
while not q.empty():
	now = q.get()
	for next in G[now]:
		if dist[next] >= 0:
			continue
		dist[next] = now
		q.put(next)
print('Yes')
for i in range(1, n):
	print(dist[i] + 1)


from collections import deque
(n, m) = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	g[a].append(b)
	g[b].append(a)
q = deque([0])
d = [-1] * n
d[0] = 1
while q:
	now = q.pop()
	for i in g[now]:
		if d[i] != -1:
			continue
		d[i] = now + 1
		q.appendleft(i)
print('Yes')
print(*d[1:], sep='\n')


from collections import deque
(N, M) = map(int, input().split())
edge = [[] for _ in range(N + 1)]
for i in range(M):
	(A, B) = map(int, input().split())
	edge[A].append(B)
	edge[B].append(A)
dist = [-1] * (N + 1)
d = deque([1])
while d:
	x = d.popleft()
	for i in range(len(edge[x])):
		if dist[edge[x][i]] == -1:
			dist[edge[x][i]] = x
			d.append(edge[x][i])
print('Yes')
print(*dist[2:], sep='\n')


from collections import deque
(N, M) = map(int, input().split())
cnct = [[] for i in range(N + 1)]
for _ in range(M):
	(A, B) = map(int, input().split())
	cnct[A].append(B)
	cnct[B].append(A)
Q = deque()
Q.append(1)
ans = [0] * (N + 1)
vstd = [0] * (N + 1)
while Q:
	temp = Q.popleft()
	for a in cnct[temp]:
		if vstd[a] == 0:
			ans[a] = temp
			vstd[a] = 1
			Q.append(a)
print('Yes')
for a in ans[2:]:
	print(a)


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) = 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()))
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)
	neighbor[edge[1] - 1].append(edge[0] - 1)
queue = deque()
queue.append(0)
back = [-1] * n
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)


from collections import deque

def input2():
	return map(int, input().split())

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()
q.append(1)
check = [0] * (n + 1)
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]:
		if check[u] == 0:
			check[u] = 1
			ans[u] = v
			q.append(u)
print('Yes')
for i in range(2, n + 1):
	print(ans[i])


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
prev = [0] * N
to_list = [[] for _ in range(N)]
for (a, b) in AB:
	to_list[a - 1].append(b - 1)
	to_list[b - 1].append(a - 1)
marked = {0}
que = [0]
for i in que:
	for j in to_list[i]:
		if j in marked:
			continue
		que.append(j)
		marked.add(j)
		prev[j] = i + 1
print('Yes')
print(*prev[1:], sep='\n')


from collections import deque
(n, m) = map(int, input().split())
r = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	r[a].append(b)
	r[b].append(a)
d = deque([0])
ans = [-1] * n
ans[0] = 0
while d:
	p = d.popleft()
	for v in r[p]:
		if ans[v] != -1:
			continue
		ans[v] = p
		d.append(v)
if -1 in ans:
	print('No')
	exit()
else:
	print('Yes')
	for v in ans[1:]:
		print(v + 1)


from collections import deque
(n, m, *L) = map(int, open(0).read().split())
con = [[] for _ in range(n)]
for (a, b) in zip(*[iter(L)] * 2):
	con[a - 1].append(b - 1)
	con[b - 1].append(a - 1)
q = deque([0])
par = [-1] * n
par[0] = 1
while q:
	cur = q.popleft()
	for nxt in con[cur]:
		if par[nxt] == -1:
			par[nxt] = cur + 1
			q.append(nxt)
if any((x == -1 for x in par)):
	print('No')
	exit()
print('Yes')
print('\n'.join(map(str, par[1:])))


from _collections import deque
(n, m) = map(int, input().split())
M = [[] for _ in range(n)]
ANS = [-1] * n
ANS[0] = 0
for i in range(m):
	(a, b) = map(int, input().split())
	M[b - 1].append(a - 1)
	M[a - 1].append(b - 1)
q = deque([0])
while q:
	s = q.popleft()
	for x in M[s]:
		if ANS[x] != -1:
			continue
		q.append(x)
		ANS[x] = s
print('Yes')
for ans in ANS[1:]:
	print(ans + 1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, bisect
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
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()
(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')


from collections import deque
(N, M) = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
	(a, b) = map(int, input().split())
	E[a - 1].append(b - 1)
	E[b - 1].append(a - 1)
q = deque()
q.append(0)
ans = [0] * N
while q:
	par = q.popleft()
	for e in E[par]:
		if ans[e] > 0:
			continue
		ans[e] = par + 1
		q.append(e)
print('Yes')
for i in range(1, N):
	print(ans[i])


(n, m) = map(int, input().split())
node = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = map(int, input().split())
	node[a - 1].append(b - 1)
	node[b - 1].append(a - 1)
from collections import deque
sign = [-1] * n
sign[0] = 0
queue = deque([0])
while queue:
	r = queue.popleft()
	for x in node[r]:
		if sign[x] == -1:
			sign[x] = r + 1
			queue.append(x)
if -1 in sign:
	print('No')
else:
	print('Yes')
	for i in range(n - 1):
		print(sign[i + 1])


((n, m), *e) = [[*map(int, t.split())] for t in open(0)]
q = [1]
ans = [0] * -~n
node = [[] for _ in range(-~n)]
temp = set()
for (i, j) in e:
	node[i].append(j)
	node[j].append(i)
while q:
	for x in q:
		for y in node[x]:
			if ans[y] == 0:
				ans[y] = x
				temp.add(y)
	q = list(temp)
	temp.clear()
if 0 in ans[2:]:
	print('No')
else:
	print('Yes', *ans[2:])


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) = map(int, input().split())
B = [[] for i in range(N)]
C = [0 for i in range(N)]
for i in range(M):
	(a, b) = map(int, input().split())
	B[a - 1].append(b)
	B[b - 1].append(a)
d = deque([1])
while len(d):
	p = d.pop()
	for q in B[p - 1]:
		if C[q - 1] == 0:
			C[q - 1] = p
			d.appendleft(q)
print('Yes')
for i in range(1, N):
	print(C[i])


from collections import deque
(N, M) = map(int, input().split())
B = [[] for i in range(N)]
for i in range(M):
	(a, b) = map(int, input().split())
	B[a - 1].append(b - 1)
	B[b - 1].append(a - 1)
visited = [0] * N
d = deque()
ans = [-1] * N
d.append(0)
visited[0] = 1
while d:
	c = d.popleft()
	for e in B[c]:
		if visited[e]:
			continue
		d.append(e)
		visited[e] = 1
		ans[e] = c
print('Yes')
for i in range(1, N):
	print(ans[i] + 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
(N, M) = map(int, input().split())
R = [[] for i in range(N + 1)]
for i in range(M):
	(A, B) = 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)


import collections
(n, m) = map(int, input().split())
g = [[] for i in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	g[a].append(b)
	g[b].append(a)
q = collections.deque()
q.append(1)
check = [0] * (n + 1)
check[1] = 1
ans = [0] * (n + 1)
while len(q) != 0:
	v = q.popleft()
	for j in g[v]:
		if check[j] == 0:
			check[j] = 1
			ans[j] = v
			q.append(j)
print('Yes')
for k in range(2, n + 1):
	print(ans[k])


(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])


import queue
(N, M) = map(int, input().split())
ans = [0] * N
q = queue.Queue()
q.put(1)
import sys
s = sys.stdin.readlines()
G = [[] for _ in range(N)]
for e in s:
	(a, b) = map(int, e.split())
	G[a - 1].append(b)
	G[b - 1].append(a)
c = 0
while c != N - 1:
	r = q.get()
	for i in G[r - 1]:
		if ans[i - 1] == 0 and i != 1:
			ans[i - 1] = r
			q.put(i)
			c += 1
print('Yes')
for i in range(N - 1):
	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])


(N, M) = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
	(A, B) = map(int, input().split())
	E[A - 1] += [B - 1]
	E[B - 1] += [A - 1]
ans = [-1] * N
T = [0]
while len(T) > 0:
	P = T
	T = []
	for x in P:
		for e in E[x]:
			if ans[e] == -1:
				T += [e]
				ans[e] = x
print('Yes')
for a in ans[1:]:
	print(a + 1)


(N, M) = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(M)]
es = [[] for _ in range(N)]
for (a, b) in AB:
	es[a - 1].append(b - 1)
	es[b - 1].append(a - 1)
ans = [-1] * N
ans[0] = 0
from collections import deque
que = deque([0])
while que:
	s = que.popleft()
	for v in es[s]:
		if ans[v] == -1:
			ans[v] = s + 1
			que.append(v)
print('Yes')
print(*ans[1:], sep='\n')


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)


import queue
(n, m) = map(int, input().split())
V = [[] for _ in range(n + 1)]
for _ in range(m):
	(a, b) = map(int, input().split())
	V[a].append(b)
	V[b].append(a)
ans = [-1] * (n + 1)
q = queue.Queue()
q.put(1)
while not q.empty():
	p = q.get()
	for c in V[p]:
		if c > 1 and ans[c] < 0:
			ans[c] = p
			q.put(c)
print('Yes')
for x in ans[2:]:
	print(x)


from collections import deque
(N, M) = map(int, input().split())
d = {i: [] for i in range(1, N + 1)}
for _ in range(M):
	(A, B) = map(int, input().split())
	d[A].append(B)
	d[B].append(A)
par = [-1] * (N + 1)
par[1] = 0
q = deque([1])
while q:
	a = q.popleft()
	for b in d[a]:
		if par[b] != -1:
			continue
		par[b] = a
		q.append(b)
print('Yes')
for i in range(2, N + 1):
	print(par[i])


(n, m) = map(int, input().split())
edges = [[] for i in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	edges[a].append(b)
	edges[b].append(a)
ans = [0 for i in range(n + 1)]
import queue
q = queue.Queue()
q.put(1)
while not q.empty():
	node = q.get()
	for e in edges[node]:
		if ans[e] == 0:
			ans[e] += node
			q.put(e)
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)]
for _ in range(m):
	(u, v) = map(int, input().split())
	G[u].append(v)
	G[v].append(u)
q = deque([1])
p = [0] * (n + 1)
while q:
	v = q.popleft()
	for u in G[v]:
		if p[u] == 0:
			p[u] = v
			q.append(u)
print('Yes\n' + '\n'.join(map(str, p[2:])))


from collections import deque
(n, m) = map(int, input().split())
g = [[] for i in range(n)]
INF = 1001001001
par = [INF for i in range(n)]
par[0] = 0
for i in range(m):
	(s, t) = map(int, input().split())
	g[s - 1].append(t - 1)
	g[t - 1].append(s - 1)
q = deque([])
q.append(0)
while q:
	now = q.popleft()
	for i in g[now]:
		if par[i] == INF:
			par[i] = now
			q.append(i)
print('Yes')
for i in range(1, n):
	print(par[i] + 1)


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])


import heapq

def dijkstra(s):
	p = [x for x in range(n)]
	hq = [(0, s)]
	heapq.heapify(hq)
	cost = [float('inf')] * n
	cost[s] = 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 = [[] 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)


(n, m) = map(int, input().split())
g = [[] for _ in range(n + 1)]
for _ in range(m):
	(a, b) = map(int, input().split())
	g[a].append(b)
	g[b].append(a)
d = {1: 0}
q = [1]
for i in q:
	for j in g[i]:
		if j not in d:
			d[j] = i
			q.append(j)
print('Yes')
for i in range(2, n + 1):
	print(d[i])


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()


from collections import deque
(n, m) = map(int, input().split())
A = [[] for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	A[b - 1].append(a - 1)
	A[a - 1].append(b - 1)
depth = [-1] * n
visit = deque([0])
while True:
	if len(visit) == 0:
		break
	x = visit.popleft()
	for i in A[x]:
		if depth[i] == -1:
			depth[i] = x + 1
			visit.append(i)
print('Yes')
[print(i) for i in depth[1:]]


(N, M) = map(int, input().split())
r = []
k = []
for i in range(N):
	k.append([])
for i in range(M):
	(a, b) = map(int, input().split())
	k[a - 1].append(b)
	k[b - 1].append(a)
d = [0] + [-1] * N
ans = [0] + [-1] * N
q = [0]
while q:
	u = q.pop(0)
	for v in range(len(k[u])):
		o = k[u][v]
		if d[o - 1] <= 0:
			d[o - 1] = d[u] + 1
			ans[o - 1] = u
			q.append(o - 1)
print('Yes')
for i in range(1, N):
	print(ans[i] + 1)


from collections import deque
(n, m) = map(int, input().split())
lst = [[] for i in range(n)]
ans = [0 for i in range(n)]
for i in range(m):
	(a, b) = list(map(int, input().split()))
	lst[a - 1].append(b - 1)
	lst[b - 1].append(a - 1)
que = deque([])
que.append(1)
while que:
	p = que.popleft()
	for i in lst[p - 1]:
		if ans[i] == 0:
			ans[i] = p
			que.append(i + 1)
print('Yes')
for i in range(1, n):
	print(ans[i])


import sys
input = sys.stdin.readline
f = lambda : map(int, input().split())
(n, m) = f()
g = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = f()
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
d = [-1] * n
from collections import deque
q = deque([0])
d[0] = 0
while q:
	p = q.popleft()
	for c in g[p]:
		if d[c] < 0:
			d[c] = p
			q.append(c)
if -1 in d:
	print('No')
else:
	print('Yes')
	for i in range(1, n):
		print(d[i] + 1)


from collections import deque
print('Yes')
(n, m) = map(int, input().split())
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)
q = deque([0])
b = [0] * n
while q:
	x = q.popleft()
	for i in g[x]:
		if b[i] != 0:
			continue
		b[i] = x + 1
		q.append(i)
print(*b[1:], 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)


f = lambda : map(int, input().split())
(n, m) = f()
g = [[] for _ in range(n)]
for _ in [0] * m:
	(a, b) = f()
	g[a - 1] += [b - 1]
	g[b - 1] += [a - 1]
p = [0] * n
from queue import *
q = Queue()
q.put(0)
while not q.empty():
	v = q.get()
	for c in g[v]:
		if p[c] < 1:
			p[c] = v + 1
			q.put(c)
print('Yes', *p[1:], sep='\n')


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()))
	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])


import queue
(N, M) = map(int, input().split())
E = [set() for i in range(N)]
for i in range(M):
	(A, B) = map(int, input().split())
	(A, B) = (A - 1, B - 1)
	E[A].add(B)
	E[B].add(A)
V = [-1] * N
q = queue.Queue()
q.put(0)
while not q.empty():
	p = q.get()
	s = E[p]
	for i in s:
		if V[i] < 0:
			V[i] = p
			q.put(i)
print('Yes')
for i in range(1, N):
	print(V[i] + 1)


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)


(n, m) = map(int, input().split())
lab = [[] for _ in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	lab[a].append(b)
	lab[b].append(a)
l = [0] * (n + 1)
num = [1]
while num:
	v = num.pop(0)
	for i in lab[v]:
		if not l[i]:
			l[i] = v
			num.append(i)
if not 0 in l[2:]:
	print('Yes')
	for i in range(2, n + 1):
		print(l[i])
else:
	print('No')


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) = map(int, input().split())
S = [[] for _ in range(N)]
for i in range(M):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	S[a].append(b)
	S[b].append(a)
q = deque()
dist = [-1] * N
dist[0] = 0
q.append(0)
while q:
	now = q.popleft()
	for j in S[now]:
		if dist[j] != -1:
			continue
		dist[j] = now + 1
		q.append(j)
print('Yes')
[print(dist[i]) for i in range(1, N)]


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) = 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])


def LI():
	return list(map(int, input().split()))

def yes():
	print('Yes')

def no():
	print('No')
from collections import deque

def main():
	(n, m) = LI()
	edge = [[] for i in range(n)]
	for i in range(m):
		(a, b) = LI()
		edge[a - 1] += (b - 1,)
		edge[b - 1] += (a - 1,)
	dq = deque([0])
	ans = [-1] * n
	while dq:
		g = dq.popleft()
		for i in edge[g]:
			if ans[i] == -1:
				ans[i] = g + 1
				dq.append(i)
	yes()
	print(*ans[1:])
main()


def main():
	from collections import deque
	(n, m) = map(int, input().split())
	ab = [[] for _ in range(n + 1)]
	for _ in range(m):
		(a, b) = map(int, input().split())
		ab[a].append(b)
		ab[b].append(a)
	l = deque([1])
	ans = [-1] * n
	while l:
		x = l.popleft()
		for i in ab[x]:
			if ans[i - 1] == -1:
				ans[i - 1] = x
				l.append(i)
	print('Yes')
	for i in ans[1:]:
		print(i)
main()


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


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 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 deque
(n, m) = map(int, input().split())
q = deque()
t = {i: set() for i in range(1, n + 1)}
v = [-1] * n
for _ in range(m):
	(a, b) = map(int, input().split())
	t[a].add(b)
	t[b].add(a)
q.append(1)
v[0] = 1
while q:
	next = q.popleft()
	for i in t[next]:
		if v[i - 1] == -1:
			q.append(i)
			v[i - 1] = next
print('Yes')
print(*v[1:], sep='\n')


(n, m) = map(int, input().split())
ls = [[] for i in range(n + 1)]
for _ in range(m):
	(p, q) = map(int, input().split())
	ls[p].append(q)
	ls[q].append(p)
ans = [None] * (n + 1)
cur = 1
que = [1]
count = 1
while que:
	cur = que.pop(0)
	for v in ls[cur]:
		if ans[v] == None:
			ans[v] = cur
			que.append(v)
print('Yes')
for s in ans[2:]:
	print(s)


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)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
G = [[] for i 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)
from collections import deque
q = [0]
q = deque(q)
ans = [-1] * n
while len(q) > 0:
	now = q.popleft()
	for i in G[now]:
		if ans[i] < 0:
			ans[i] = now
			q.append(i)
print('Yes')
for i in range(1, n):
	print(ans[i] + 1)


from collections import deque
(n, m) = map(int, input().split())
to = [[] for i 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)
dist = [None] * n
que = deque([0])
while que:
	v = que.pop()
	for i in to[v]:
		if dist[i] is None:
			dist[i] = v + 1
			que.appendleft(i)
print('Yes')
for i in dist[1:]:
	print(i)


(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('Yes')
for i in range(1, N):
	print(pre[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)
	d = [None] * (N + 1)
	d[u] = 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
ans = bfs(1)
print('Yes')
for i in range(2, N + 1):
	print(ans[i])


import sys
from collections import *
(N, M) = map(int, input().split())
adj = [[] for _ in range(N + 1)]
for ln in sys.stdin:
	(A, B) = map(int, ln.split())
	adj[A].append(B)
	adj[B].append(A)
ans = [0] * (N + 1)
ans[1] = 1
que = deque([1])
while que:
	A = que.popleft()
	for B in adj[A]:
		if ans[B] == 0:
			ans[B] = A
			que.append(B)
print('Yes')
for i in range(2, N + 1):
	print(ans[i])


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)


import sys
sys.setrecursionlimit(500 * 500)
from collections import deque
(N, M) = map(int, input().split())
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)
print('Yes')
print(*ans[2:], sep='\n')


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 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[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())
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())
turo = [[] for _ in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	turo[a].append(b)
	turo[b].append(a)
q = deque([1])
heya = [0] * (n + 1)
heya[1] = 1
mejirushi = [0] * (n + 1)
while len(q) != 0:
	v = q.popleft()
	for i in turo[v]:
		if heya[i] == 0:
			heya[i] = 1
			mejirushi[i] = v
			q.append(i)
print('Yes')
for i in range(2, n + 1):
	print(mejirushi[i])


from collections import deque

def main():
	(n, m) = map(int, input().split())
	e = [[] for _ in range(n)]
	for _ in range(m):
		(a, b) = map(int, input().split())
		a -= 1
		b -= 1
		e[a].append(b)
		e[b].append(a)
	ans = [-1] * n
	dq = deque([0])
	while dq:
		g = dq.popleft()
		for v in e[g]:
			if ans[v] == -1:
				ans[v] = g + 1
				dq.append(v)
	ans[0] = 'Yes'
	print(*ans)
main()


from collections import deque
from sys import stdin
nii = lambda : map(int, stdin.readline().split())
(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] = 0
dq = deque()
dq.append(0)
while dq:
	x = dq.popleft()
	for i in tree[x]:
		if ans[i] == -1:
			ans[i] = x
			dq.append(i)
print('Yes')
for i in ans[1:]:
	print(i + 1)


(n, m) = list(map(int, input().split()))
r = [[] for i in range(n)]
for i in range(m):
	inp = list(map(lambda x: int(x) - 1, input().split()))
	r[inp[0]].append(inp[1])
	r[inp[1]].append(inp[0])
w = [0 for i in range(n)]
w[0] = 1
a = [0]
b = []
while True:
	for i in a:
		for j in r[i]:
			if w[j] == 0:
				w[j] = i + 1
				b.append(j)
	if len(b) == 0:
		break
	a = b
	b = []
print('Yes')
for i in range(1, n):
	print(w[i])


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())
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
(n, m) = list(map(int, input().split()))
roads = [[] for _ in range(n + 1)]
for _ in range(m):
	(a, b) = list(map(int, input().split()))
	roads[a].append(b)
	roads[b].append(a)
ans = [-1 for _ in range(n + 1)]
q = deque()
q.append(1)
while q:
	cur = q.popleft()
	for dest in roads[cur]:
		if ans[dest] == -1:
			ans[dest] = cur
			q.append(dest)
print('Yes')
for i in range(2, n + 1):
	print(ans[i])


from collections import deque
(N, M) = map(int, input().split())
m = [[] for _ in range(N)]
n = [-1] * N
n[0] = 0
for _ in range(M):
	(a, b) = map(int, input().split())
	m[a - 1].append(b - 1)
	m[b - 1].append(a - 1)

def bfs():
	que = deque([])
	que.append(0)
	while que:
		p = que.popleft()
		for i in m[p]:
			if n[i] == -1:
				que.append(i)
				n[i] = p + 1
bfs()
print('Yes')
for j in range(1, N):
	print(n[j])


from collections import deque
(n, m) = map(int, input().split())
net = [[] for _ in range(n + 1)]
for _ in range(m):
	(a, b) = map(int, input().split())
	net[a].append(b)
	net[b].append(a)
a = [-1] * (n + 1)
d = deque()
d.append(1)
while d:
	u = d.popleft()
	for child in net[u]:
		if a[child] != -1:
			continue
		a[child] = u
		d.append(child)
print('Yes')
print(*a[2:], sep=' ')


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)
ans = [0] * (n + 1)
q = collections.deque()
q.append(1)
count = [0] * (n + 1)
count[1] = 1
while len(q) != 0:
	v = q.popleft()
	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) = map(int, input().split())
t = []
l = [0] * (n + 1)
for i in range(n + 1):
	t.append([])
for i in range(m):
	(a, b) = map(int, input().split())
	t[a].append(b)
	t[b].append(a)
x = [1]
p = 0
while p < n:
	for i in range(len(t[x[p]])):
		c = t[x[p]][i]
		if l[c] == 0:
			x.append(c)
			l[c] = x[p]
	p += 1
print('Yes')
for i in range(2, n + 1):
	print(l[i])


from collections import deque
(n, m) = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	g[a].append(b)
	g[b].append(a)
stack = deque([0])
dist = [-1] * n
dist[0] = 0
while stack:
	v = stack.popleft()
	for nv in g[v]:
		if dist[nv] == -1:
			dist[nv] = v + 1
			stack.append(nv)
print('Yes')
print(*dist[1:], sep='\n')


((n, m), *t) = [map(int, t.split()) for t in open(0)]
(*e,) = eval('[],' * -~n)
for (a, b) in t:
	e[a] += (b,)
	e[b] += (a,)
q = [1]
d = [0] * -~n
for v in q:
	for w in e[v]:
		if d[w] < 1:
			d[w] = v
			q += (w,)
print('Yes', *d[2:])


(n, m) = map(int, input().split())
room = [[] for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	room[a - 1].append(b - 1)
	room[b - 1].append(a - 1)
mark = [-1] * n
mark[0] = 0
q = []
q.append(0)
while len(q):
	now = q.pop(0)
	for i in room[now]:
		if mark[i] == -1:
			mark[i] = now
			q.append(i)
print('Yes')
for i in mark[1:]:
	print(i + 1)


from collections import deque
(n, m) = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
	(x, y) = map(int, input().split())
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)
a = [-1] * n
d = deque([0])
while d:
	f = d.popleft()
	for o in g[f]:
		if a[o] == -1:
			a[o] = f
			d.append(o)
print('Yes')
for i in a[1:]:
	print(i + 1)


from collections import deque
(n, m) = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
	(x, y) = map(int, input().split())
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)
ans = [-1] * n
deq = deque([0])
while deq:
	fr = deq.popleft()
	for go in g[fr]:
		if ans[go] == -1:
			ans[go] = fr
			deq.append(go)
print('Yes')
for i in ans[1:]:
	print(i + 1)


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])


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)
p = [0] * N
que = deque([0])
while que:
	v = que.popleft()
	for i in graph[v]:
		if p[i] < 1:
			p[i] = v + 1
			que.append(i)
if 0 in p:
	print('No')
else:
	print('Yes', *p[1:], 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()


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


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])


(n, m) = map(int, input().split())
l = [[] for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	l[a - 1].append(b - 1)
	l[b - 1].append(a - 1)
done = [False for i in range(n)]
ans = [-1 for i in range(n)]

def bfs():
	que = [0]
	while que:
		now = que.pop(0)
		done[now] = True
		for i in l[now]:
			if done[i] == False:
				que.append(i)
				done[i] = True
				ans[i] = now + 1
bfs()
print('Yes')
print(*ans[1:])


(n, m) = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = [int(i) - 1 for i in input().split()]
	e[a].append(b)
	e[b].append(a)
ans = [-2] * n
ans[0] = -1
q = [0]
for i in q:
	for j in e[i]:
		if ans[j] == -2:
			q.append(j)
			ans[j] = i
if -2 in ans:
	print('No')
else:
	print('Yes')
	for i in ans[1:]:
		print(i + 1)


from collections import deque
q = deque()

def MI():
	return map(int, input().split())
(N, M) = MI()
g = [[] for _ in range(N + 1)]
for _ in range(M):
	(a, b) = MI()
	g[a].append(b)
	g[b].append(a)
check = [0] * (N + 1)
check[1] = 1
ans = [0] * (N + 1)
q.append(1)
while len(q) > 0:
	v = q.popleft()
	for u in g[v]:
		if check[u] == 0:
			check[u] = 1
			ans[u] = v
			q.append(u)
print('Yes')
for i in range(2, N + 1):
	print(ans[i])


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())
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])


from collections import deque
(N, M) = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
	(A, B) = map(int, input().split())
	A -= 1
	B -= 1
	G[A].append(B)
	G[B].append(A)
searched = [0] * N
searched[0] = 1
ans = [-1] * N
d = deque()
d.append(0)
while len(d) != 0:
	tmp = d.popleft()
	for g in G[tmp]:
		if searched[g] == 0:
			searched[g] = 1
			d.append(g)
			ans[g] = tmp
print('Yes')
for i in ans[1:]:
	print(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('Yes')
for j in range(2, N + 1):
	print(ans[j])


(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')


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])


from collections import deque
R = lambda : map(int, input().split())
(n, m) = R()
g = [[] for _ in range(n)]
for _ in range(m):
	(u, v) = R()
	g[u - 1].append(v - 1)
	g[v - 1].append(u - 1)
r = [None] * (n - 1)
V = [True] + [False] * (n - 1)
q = deque([0])
while q:
	u = q.popleft()
	for v in g[u]:
		if not V[v]:
			V[v] = True
			r[v - 1] = u + 1
			q.append(v)
print(*(['No'], ['Yes'] + r)[all(r)], sep='\n')


import threading, queue
(N, M) = map(int, input().split())
ans = [-1 for i in range(N + 1)]
E = [[] for i in range(N + 1)]
for i in range(M):
	(a, b) = map(int, input().split())
	E[a].append(b)
	E[b].append(a)
q = queue.Queue(N)
q.put(1)
ans[1] = 0
while q.empty() == False:
	t = q.get()
	for j in E[t]:
		if ans[j] == -1:
			ans[j] = t
			q.put(j)
print('Yes')
for i in range(2, N + 1):
	print(ans[i])


from collections import deque
(n, m) = map(int, input().split())
node = [[] for _ in range(n)]
for i in range(m):
	(x, y) = map(int, input().split())
	node[x - 1].append(y - 1)
	node[y - 1].append(x - 1)
d = deque()
seen = [-1] * n
d.append(0)
while d:
	vi = d.popleft()
	for i in node[vi]:
		if seen[i] == -1:
			d.append(i)
			seen[i] = vi
if '-1' in seen:
	print('No')
else:
	print('Yes')
	for i in range(1, len(seen)):
		print(seen[i] + 1)


from collections import deque
(n, m) = map(int, input().split())
maze = [[] for i in range(n)]
for i in range(m):
	(r, l) = map(int, input().split())
	maze[r - 1].append(l - 1)
	maze[l - 1].append(r - 1)
stamp = [-1] * n
queue = deque([0])
while queue:
	d = queue.popleft()
	for i in maze[d]:
		if stamp[i] == -1:
			stamp[i] = d
			queue.append(i)
print('Yes')
for i in range(1, n, 1):
	print(stamp[i] + 1)


(N, M) = map(int, input().split())
G = [[] for _ in range(N + 1)]
for _ in range(M):
	(A, B) = map(int, input().split())
	G[A].append(B)
	G[B].append(A)
D = [None] * (N + 1)
D[1] = 0
Q = set([1])
while len(Q) > 0:
	Q2 = set()
	for q in Q:
		for r in G[q]:
			if D[r] == None:
				D[r] = q
				Q2.add(r)
	Q = Q2
print('Yes')
for d in D[2:]:
	print(d)


from heapq import heappush, heapify, heappop

def dijkstra(start: '始点', V: '頂点数', es: '隣接リスト', INF=10000000000):
	prev = [-1] * n
	d = [INF] * n
	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)]
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())
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])


(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)


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())
graph = [[] for i in range(n)]
roomSign = [-1] * 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])
while D:
	v = D.popleft()
	for i in graph[v]:
		if roomSign[i] == -1:
			roomSign[i] = v
			D.append(i)
print('Yes')
for i in range(1, n):
	print(roomSign[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)
d = [0] * (n + 1)
q = deque()
q.append(1)
while q:
	v = q.popleft()
	for j in graph[v]:
		if not d[j]:
			q.append(j)
			d[j] = v
print('Yes')
for x in range(2, n + 1):
	print(d[x])


(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)
ANS = [0 for i in range(N)]
finish = [0]
for i in finish:
	for k in graph[i]:
		if ANS[k] == 0:
			ANS[k] = i + 1
			finish.append(k)
print('Yes')
for i in range(1, N):
	ans = ANS[i]
	print(ans)


it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
	itf = input()
	itf = itf.split()
	a = int(itf[0])
	b = int(itf[1])
	p[a - 1].append(b)
	p[b - 1].append(a)
d = [1]
con = [0] * n
while d:
	l = d.pop(0)
	for k in p[l - 1]:
		if con[k - 2] == 0:
			d.append(k)
			con[k - 2] = l
print('Yes')
for i in range(n - 1):
	print(con[i])


import collections
(N, M) = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(M)]
ans = [None] * (N + 1)
G = collections.defaultdict(set)
for (a, b) in AB:
	G[a].add(b)
	G[b].add(a)
Q = collections.deque([1])
while Q:
	i = Q.popleft()
	for j in G[i]:
		if ans[j] is None:
			Q += [j]
			ans[j] = i
print('Yes')
print('\n'.join(map(str, ans[2:])))


from collections import deque
print('Yes')
(N, M) = map(int, input().split())
lst = [[] for _ in range(N)]
for _ in range(M):
	(a, b) = map(int, input().split())
	lst[a - 1].append(b - 1)
	lst[b - 1].append(a - 1)
q = deque(lst[0])
go = [None] * N
for i in lst[0]:
	go[i] = 0
while q:
	v = q.popleft()
	for new in lst[v]:
		if go[new] == None:
			go[new] = v
			q.append(new)
for i in go[1:]:
	print(i + 1)


(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())
root = [[] for _ in range(n)]
adj = [-1 for _ in range(n)]
for _ in range(m):
	(r, c) = map(int, input().split())
	root[r - 1].append(c - 1)
	root[c - 1].append(r - 1)
explor = deque()
explor.append(0)
while explor:
	tmp = explor.popleft()
	for i in root[tmp]:
		if adj[i] == -1:
			adj[i] = tmp
			explor.append(i)
print('Yes')
for i in adj[1:]:
	print(i + 1)


(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('Yes')
for j in range(2, N + 1):
	print(ans[j])


from collections import deque
(n, m) = map(int, input().split())
ab = [[] for _ in range(n + 1)]
for _ in range(m):
	(a, b) = map(int, input().split())
	ab[a].append(b)
	ab[b].append(a)
ans = [0] * (n + 1)
ans[1] = 1
que = deque()
que.append(1)
while que:
	x = que.popleft()
	for i in ab[x]:
		if ans[i] == 0:
			ans[i] = x
			que.append(i)
print('Yes')
for j in range(2, n + 1):
	print(ans[j])


import queue
(N, M) = map(int, input().split())
r = [[] for _ in range(N)]
for i in range(M):
	(A, B) = map(int, input().split())
	r[A - 1].append(B)
	r[B - 1].append(A)
ans = [0] * (N + 1)
q = queue.Queue()
q.put(1)
while not q.empty():
	qg = q.get()
	for ri in r[qg - 1]:
		if ans[ri] == 0:
			ans[ri] = qg
			q.put(ri)
print('Yes')
for i in range(2, N + 1):
	print(ans[i])


from collections import deque
(N, M) = map(int, input().split())
root = [[] for _ in range(N)]
for _ in range(M):
	(a, b) = map(int, input().split())
	root[a - 1].append(b)
	root[b - 1].append(a)
q = deque()
q.append(1)
ans = [0 for _ in range(N)]
while len(q) > 0:
	v = q.popleft()
	for ike in root[v - 1]:
		q.append(ike)
		if ans[ike - 1] == 0:
			ans[ike - 1] = v
	root[v - 1].clear()
print('Yes')
for a in ans[1:]:
	print(a)


import queue
(N, M) = map(int, input().split())
adj = [[] for i in [0] * N]
for i in [0] * M:
	(a, b) = map(int, input().split())
	adj[a - 1].append(b)
	adj[b - 1].append(a)
que = queue.Queue()
que.put(1)
guide = [-1] * N
while not que.empty():
	x = que.get()
	for y in adj[x - 1]:
		if guide[y - 1] == -1:
			que.put(y)
			guide[y - 1] = x
print('Yes')
for i in guide[1:]:
	print(i)


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()))
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
		visited[ne] = 1
for i in range(1, n):
	print(ans[i] + 1)


(n, m) = map(int, input().split())
g = [[] for i 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)
p = [-1] * n
q = [0]
while q:
	i = q.pop(0)
	for j in g[i]:
		if p[j] == -1:
			p[j] = i
			q.append(j)
print('Yes')
for i in range(1, n):
	print(p[i] + 1)


(N, M) = map(int, input().split())
l = [set() for i in range(N)]
for i in range(M):
	(a, b) = map(int, input().split())
	l[a - 1].add(b - 1)
	l[b - 1].add(a - 1)
ope = [1] * N
ope[0] = 0
s = {0}
ans = [-1] * N
while len(s):
	news = set()
	for j in s:
		for k in l[j]:
			if ope[k]:
				news.add(k)
				ans[k] = j
				ope[k] = 0
	s = news
print('Yes')
for i in range(1, N):
	print(ans[i] + 1)


import collections
(n, m) = list(map(int, input().split()))
di = collections.defaultdict(list)
for i in range(m):
	(a, b) = list(map(int, input().split()))
	di[a - 1].append(b - 1)
	di[b - 1].append(a - 1)
ans = [-1] * n
ans[0] = 0
que = [0]
while que:
	v = que.pop(0)
	for i in di[v]:
		if ans[i] != -1:
			continue
		ans[i] = v
		que.append(i)
print('Yes')
for i in ans[1:]:
	print(i + 1)


(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


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')


from collections import deque
(N, M) = list(map(int, input().split()))
g = [[] for i in range(N)]
for _ in range(M):
	(A, B) = list(map(int, input().split()))
	g[A - 1].append(B - 1)
	g[B - 1].append(A - 1)
visited = [-1] * N
q = deque([0])
while q:
	p = q.popleft()
	for node in g[p]:
		if visited[node] == -1:
			visited[node] = p + 1
			q.append(node)
print('Yes')
print('\n'.join(map(str, visited[1:])))


from collections import deque
(n, m) = map(int, input().split())
g = [[] for i in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	g[a].append(b)
	g[b].append(a)
ans = [None] * (n + 1)
q = deque([1])
ans[1] = 0
while q:
	now = q.popleft()
	for next in g[now]:
		if ans[next] == None:
			ans[next] = now
			q.append(next)
print('Yes')
for i in range(2, n + 1):
	print(ans[i])


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)

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:
		q = queue.popleft()
		seen[q] = True
		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)
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
print(ans)
if ans == 'Yes':
	[print(s + 1) for s in sign[1:]]


from collections import deque
(N, M) = map(int, input().split())
X = [[] for x in range(N + 1)]
for m in range(M):
	(A, B) = map(int, input().split())
	X[A].append(B)
	X[B].append(A)
Q = deque()
Q.append(1)
D = [-1] * (N + 1)
D[0] = 0
D[1] = 0
while Q:
	v = Q.pop()
	for i in X[v]:
		if D[i] == -1:
			D[i] = v
			Q.appendleft(i)
if -1 in D:
	print('No')
else:
	print('Yes')
	print(*D[2:])


(n, m) = map(int, input().split())
e = [set() for _ in range(n)]
for _ in range(m):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	e[a].add(b)
	e[b].add(a)
p = [-1] * n
p[0] = 0
q = [0]
while len(q) > 0:
	u = q.pop(0)
	for v in e[u]:
		if p[v] == -1:
			p[v] = u
			q.append(v)
if min(p) == -1:
	print('No')
else:
	print('Yes')
	for i in range(1, n):
		print(p[i] + 1)


from collections import deque
(n, m) = map(int, input().split())
data = [[] for i in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	data[a].append(b)
	data[b].append(a)
que = deque()
que.append(1)
cnt = [0] * (n + 1)
while que:
	h = que.popleft()
	for u in data[h]:
		if cnt[u] != 0:
			continue
		cnt[u] = h
		que.append(u)
print('Yes')
for i in range(2, n + 1):
	print(cnt[i])


(N, M) = map(int, input().split())
to = [[] for _ in range(N)]
ans = [-1] * N
for _ in range(M):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	to[a].append(b)
	to[b].append(a)
from collections import deque
Q = deque([0])
ans[0] = -2
while Q:
	v = Q.popleft()
	for s in to[v]:
		if ans[s] == -1:
			ans[s] = v
			Q.append(s)
print('Yes')
print(*(a + 1 for a in ans[1:]), sep='\n')


import sys
from itertools import chain
YES = 'Yes'

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 = int(next(tokens))
	M = int(next(tokens))
	A = [int()] * M
	B = [int()] * M
	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()


(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)
milestone = [0] * (n + 1)
q = []
q.append(1)
while len(q) != 0:
	for i in graph[q[0]]:
		if milestone[i] == 0:
			milestone[i] = q[0]
			q.append(i)
	q.pop(0)
print('Yes')
for i in range(2, n + 1):
	print(milestone[i])


from collections import deque
(n, m) = map(int, input().split())
g = [[] for _ in range(n + 1)]
for _ in range(m):
	(a, b) = map(int, input().split())
	g[a].append([a, b])
	g[b].append([b, a])
res = [-1 for _ in range(n + 1)]
res[1] = 0
q = deque(g[1])
while q:
	q_ = q.popleft()
	if res[q_[1]] == -1:
		for gi in g[q_[1]]:
			q.append(gi)
		res[q_[1]] = q_[0]
print('Yes')
for i in res[2:]:
	print(i)


(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 = [1]
while d:
	c = d.pop(0)
	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())
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')


(n, m) = map(int, input().split())
link = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = map(int, input().split())
	link[a - 1].append(b - 1)
	link[b - 1].append(a - 1)
q = [0]
visited = [0] * n
visited[0] = 1
while q:
	x = q.pop(0)
	for i in link[x]:
		if visited[i] == 0:
			visited[i] = x + 1
			q.append(i)
print('Yes')
print(*visited[1:], sep='\n')


(N, M) = map(int, input().split())
G = []
for i in range(0, N):
	G.append([])
for i in range(0, M):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	G[a].append(b)
	G[b].append(a)
q = []
sign = [-1] * N
sign[0] = 0
q.append(0)
while q:
	x = q.pop(0)
	for nv in G[x]:
		if sign[nv] == -1:
			sign[nv] = x
			q.append(nv)
print('Yes')
for i in range(1, N):
	print(sign[i] + 1)


from collections import deque
(n, m) = map(int, input().split())
g = [[] for i in range(n)]
mark = [0] * n
for i in range(m):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	g[a].append(b)
	g[b].append(a)
D = deque([0])
visited = [False] * n
visited[0] = True
while D:
	v = D.popleft()
	for i in g[v]:
		if visited[i]:
			continue
		visited[i] = True
		mark[i] = v
		D.append(i)
print('Yes')
for i in range(1, n):
	print(mark[i] + 1)


import queue
(n, m) = map(int, input().split())
G = [[] for i in range(n)]
for _ in range(m):
	(y, yy) = map(int, input().split())
	y -= 1
	yy -= 1
	G[y].append(yy)
	G[yy].append(y)
q = queue.Queue()
vis = [0] * n
mae = [-1] * n
q.put([0, 0])
while q.empty() == False:
	r = q.get()
	if vis[r[0]] == 1:
		continue
	vis[r[0]] = 1
	mae[r[0]] = r[1]
	for v in G[r[0]]:
		if vis[v] == 0:
			q.put([v, r[0]])
print('Yes')
for i in range(1, n):
	print(mae[i] + 1)


import queue
(n, m) = map(int, input().split())
e = [[] for _ in range(n + 1)]
INF = 10 ** 18
d = [INF] * (n + 1)
ans = [0] * (n + 1)
for _ in range(m):
	(a, b) = map(int, input().split())
	e[a] += [b]
	e[b] += [a]
q = queue.Queue()
q.put(1)
d[1] = 0
while not q.empty():
	now = q.get()
	for to in e[now]:
		if d[to] == INF:
			ans[to] = now
			d[to] = d[now] + 1
			q.put(to)
print('Yes')
for i in ans[2:]:
	print(i)


from collections import deque
(N, M) = map(int, input().split())
AB = [[] for i in range(N)]
for i in range(M):
	(A, B) = map(int, input().split())
	AB[A - 1].append(B)
	AB[B - 1].append(A)
print('Yes')
D = deque([1])
ans = [0] * N
ans[0] = -1
for i in range(N - 1):
	C = D.popleft()
	for j in AB[C - 1]:
		if ans[j - 1] == 0:
			ans[j - 1] = C
			D.append(j)
for i in range(1, N):
	print(ans[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) = 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()


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)
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])


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])


(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)
lst = [0] * (n - 1)
visited = set()
queue = [[0, set([1])]]
while queue:
	(pre_room, rooms) = queue.pop(0)
	for room in rooms:
		if room in visited:
			continue
		if lst[room - 2] == 0 and room != 1:
			lst[room - 2] = pre_room
		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])


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


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())
l = [[0] for _ in range(n + 1)]
vi = [0 for _ in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	l[a].append(b)
	l[b].append(a)
st = deque([1])
f = set([1])
while st:
	x = st.popleft()
	for k in l[x]:
		if k not in f:
			st.append(k)
			f.add(k)
			vi[k] = x
print('Yes')
for m in vi[2:]:
	print(m)


(n, m) = map(int, input().split())
l = [[] for _ in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	l[a - 1].append(b - 1)
	l[b - 1].append(a - 1)
queue = [0]
visit = [0] * n
visit[0] = 1
ans = [0] * n
while len(queue) > 0:
	now = queue.pop(0)
	for p in l[now]:
		if visit[p] == 0:
			visit[p] += 1
			queue.append(p)
			ans[p] = now + 1
k = ans[1:]
if not all((kk != 0 for kk in k)):
	print('No')
	exit()
print('Yes')
for kk in k:
	print(kk)


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) = 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')