Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!

He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!

The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.

Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition.


-----Input-----

The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree.

Each of the next $n - 1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree.


-----Output-----

If there are no decompositions, print the only line containing "No".

Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$. 

Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of the paths in the decomposition is the simple path between nodes $u_i$ and $v_i$. 

Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.

If there are multiple decompositions, print any.


-----Examples-----
Input
4
1 2
2 3
3 4

Output
Yes
1
1 4

Input
6
1 2
2 3
3 4
2 5
3 6

Output
No

Input
5
1 2
1 3
1 4
1 5

Output
Yes
4
1 2
1 3
1 4
1 5



-----Note-----

The tree from the first example is shown on the picture below: [Image] The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.

The tree from the second example is shown on the picture below: [Image] We can show that there are no valid decompositions of this tree.

The tree from the third example is shown on the picture below: [Image] The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.

Difficulty: MEDIUM

Solutions:
n = int(input().strip())
degs = [0 for _ in range(n)]
for _ in range(n - 1):
	[u, v] = map(int, input().strip().split())
	degs[u - 1] += 1
	degs[v - 1] += 1
ni = [None, [], [], []]
for (v, d) in enumerate(degs):
	dd = min(d, 3)
	ni[dd].append(v)
if len(ni[3]) > 1:
	print('No')
elif len(ni[3]) == 1:
	print('Yes')
	print(len(ni[1]))
	u = ni[3][0]
	for v in ni[1]:
		print(u + 1, v + 1)
else:
	print('Yes')
	print(1)
	print(ni[1][0] + 1, ni[1][1] + 1)


def readline():
	return tuple(map(int, input().split()))

def readlines(count):
	return (readline() for __ in range(count))

def main():
	(n,) = readline()
	degree = [0] * n
	root = None
	for (a, b) in readlines(n - 1):
		degree[a - 1] += 1
		degree[b - 1] += 1
	for (x, d) in enumerate(degree, start=1):
		if d > 2:
			if root is None:
				root = x
			else:
				print('No')
				return
	if root is None:
		root = 1
	ways = [i for (i, d) in enumerate(degree, start=1) if d == 1 and i != root]
	print('Yes')
	print(len(ways))
	print('\n'.join(map(f'{root} {{}}'.format, ways)))
main()


import sys, math
n = int(input())
tree = [[] for i in range(n)]
degree = [0] * n
for i in range(n - 1):
	(u, v) = map(int, sys.stdin.readline().split())
	tree[u - 1].append(v)
	tree[v - 1].append(u)
	degree[u - 1] += 1
	degree[v - 1] += 1
x = 0
for i in range(n):
	if degree[i] >= 3:
		x += 1
if x == 0:
	print('Yes')
	a = 0
	b = 0
	flag = True
	for i in range(n):
		if degree[i] == 1 and flag:
			a = i + 1
			flag = False
		elif degree[i] == 1:
			b = i + 1
	print(1)
	print(a, b)
elif x > 1:
	print('No')
else:
	print('Yes')
	max_degree = degree.index(max(degree)) + 1
	ans = []
	for i in range(n):
		if degree[i] == 1:
			ans.append([max_degree, i + 1])
	print(len(ans))
	for i in range(len(ans)):
		print(*ans[i])


n = int(input())
flag = True
f = [0] * (n - 1)
t = [0] * (n - 1)
co = [0] * n
for i in range(n - 1):
	(f[i], t[i]) = map(int, input().split())
	co[f[i] - 1] += 1
	co[t[i] - 1] += 1
mid = 0
en = []
for i in range(n):
	if co[i] == 1:
		en.append(i + 1)
	elif co[i] > 2:
		if mid == 0:
			mid = i + 1
		else:
			print('No')
			flag = False
			break
if flag:
	print('Yes')
	if mid != 0:
		print(len(en))
		for i in range(len(en)):
			print(mid, en[i])
	else:
		print(1)
		print(en[0], en[1])


from math import *

def main():
	n = int(input())
	Edge = [[] for i in range(n + 3)]
	for i in range(1, n):
		(u, v) = map(int, input().split())
		Edge[u].append(v)
		Edge[v].append(u)
	cnt = 0
	ComPo = []
	for i in range(1, n + 1):
		if len(Edge[i]) > 2:
			cnt += 1
			ComPo.append(i)
	if cnt > 1:
		print('No')
	else:
		print('Yes')
		if cnt == 0:
			print(1)
			for i in range(1, n + 1):
				if len(Edge[i]) == 1:
					ComPo.append(i)
			print(ComPo[0], ComPo[1])
		else:
			Ans = []
			for i in range(1, n + 1):
				if len(Edge[i]) == 1:
					Ans.append(i)
			print(len(Ans))
			for i in Ans:
				print(ComPo[0], i)
try:
	while True:
		main()
except EOFError:
	pass


N = int(input())
cnt = [0] * N
G = [[] for i in range(N)]
rec = []
for i in range(N - 1):
	(a, b) = map(int, input().split())
	cnt[a - 1] += 1
	cnt[b - 1] += 1
rec = []
num = 0
root = 0
for i in range(N):
	if cnt[i] > 2:
		num += 1
		root = i
	elif cnt[i] == 1:
		rec.append(i)
if num >= 2:
	print('No')
elif num == 0:
	print('Yes')
	print(1)
	print(rec[0] + 1, rec[1] + 1)
else:
	print('Yes')
	print(len(rec))
	for i in range(len(rec)):
		print('{} {}'.format(root + 1, rec[i] + 1))


n = int(input())
d = [0] * 100010
l = []
le = []
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	d[u] += 1
	d[v] += 1
	l.append(u)
	l.append(v)
r = 0
for i in range(1, max(l) + 1):
	if d[i] == 1:
		le.append(i)
	if d[i] > 2:
		if not r:
			r = i
		else:
			print('No')
			exit(0)
print('Yes')
if not r:
	print(1)
	print(min(le), max(le))
else:
	x = len(le)
	print(x)
	le.sort()
	for i in range(1, x + 1):
		print(r, le[i - 1])


from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
n = ii1()
deg = [0] * n
for i in range(n - 1):
	(a, b) = iia()
	deg[a - 1] += 1
	deg[b - 1] += 1
count = node = 0
ans = []
for i in range(n):
	if deg[i] > 2:
		count += 1
		node = i
	elif deg[i] == 1:
		ans.append(i)
if count > 1:
	print('No')
else:
	print('Yes')
	print(deg[node])
	for i in ans:
		if node != i:
			print(node + 1, i + 1)


n = int(input())
ind = [0] * (n + 1)
cnt = 0
for i in range(n - 1):
	(u, v) = map(int, input().split())
	ind[u] += 1
	ind[v] += 1
ok = sum((ind[i] > 2 for i in range(1, n + 1))) < 2
if not ok:
	print('No')
	exit()
print('Yes')
centre = ind.index(max(ind))
leaf = []
for i in range(1, n + 1):
	if ind[i] == 1:
		leaf.append(i)
if max(ind) == 2 or n == 2:
	print(1)
	print(leaf[0], leaf[1])
else:
	print(len(leaf))
	for i in leaf:
		print(*[centre, i])


n = int(input())
g = [0 for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1] += 1
	g[b - 1] += 1
q = 0
k = 0
kind = 0
m = 0
for i in range(n):
	if g[i] == 1:
		m += 1
	if g[i] > 2:
		if g[i] > k:
			kind = i
			k = g[i]
		q += 1
if q > 1:
	print('No')
else:
	print('Yes')
	if k > 2:
		print(m)
		for i in range(n):
			if g[i] == 1:
				print(kind + 1, i + 1)
	else:
		print(1)
		for i in range(n):
			if g[i] == 1:
				print(i + 1, end=' ')


def main():
	n = int(input())
	deg = [0] * n
	for i in range(n - 1):
		(u, v) = map(int, input().split())
		deg[u - 1] += 1
		deg[v - 1] += 1
	count = 0
	ans = 0
	e = []
	for i in range(n):
		if deg[i] > 2:
			count += 1
			ans = i
		if deg[i] == 1:
			e.append(i)
	if count > 1:
		print('No')
	else:
		print('Yes')
		print(deg[ans])
		for el in e:
			if el != ans:
				print(ans + 1, el + 1)
main()


from copy import deepcopy
import itertools
from bisect import bisect_left

def read():
	return int(input())

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

def readlist():
	return list(map(int, input().split()))
N = read()
degree = [0] * N
for _ in range(N - 1):
	(a, b) = readmap()
	degree[a - 1] += 1
	degree[b - 1] += 1
more_than_three = 0
for d in degree:
	if d >= 3:
		more_than_three += 1
if more_than_three >= 2:
	print('No')
	quit()
ans = []
if more_than_three == 1:
	for v in range(N):
		if degree[v] >= 3:
			center = v
	for v in range(N):
		if degree[v] == 1:
			ans.append((center + 1, v + 1))
	print('Yes')
	print(len(ans))
	for tup in ans:
		print(tup[0], tup[1])
	quit()
leaf = []
for v in range(N):
	if degree[v] == 1:
		leaf.append(v)
print('Yes')
print(1)
print(leaf[0] + 1, leaf[1] + 1)


import sys
sys.setrecursionlimit(100001)
n = int(input())
adjlist = [[] for i in range(n)]
number = [0 for i in range(n)]
visited = [0 for i in range(n)]
i = 0
while i < n - 1:
	(a, b) = [int(j) for j in input().split()]
	adjlist[a - 1].append(b - 1)
	adjlist[b - 1].append(a - 1)
	i += 1
contador = 0
raiz = 0
i = 0
while i < n:
	if len(adjlist[i]) > 2:
		contador += 1
		raiz = i
	i += 1
if contador <= 1:
	print('Yes')
	folhas = []
	i = 0
	while i < n:
		if len(adjlist[i]) == 1 and i != raiz:
			folhas.append('%d %d' % (raiz + 1, i + 1))
		i += 1
	print(len(folhas))
	print('\n'.join(folhas))
else:
	print('No')


n = int(input())
orders = [0 for i in range(n)]
for i in range(n - 1):
	(a, b) = [int(j) - 1 for j in input().split()]
	orders[a] += 1
	orders[b] += 1
roots = []
leafs = []
for (i, x) in enumerate(orders):
	if x > 2:
		roots.append(i)
	elif x == 2:
		pass
	elif x == 1:
		leafs.append(i)
	else:
		raise Exception('woww')
if len(roots) > 1:
	print('No')
elif len(roots) == 0:
	print('Yes')
	print('1')
	print(' '.join([str(l + 1) for l in leafs]))
elif len(roots) == 1:
	print('Yes')
	print(str(len(leafs)))
	root = str(roots[0] + 1)
	for l in leafs:
		print(root, str(l + 1))
else:
	raise Exception('woww')


n = int(input())
dic = {}
for i in range(n):
	dic.update({i + 1: 0})
for i in range(n - 1):
	s = input().split()
	dic[int(s[0])] += 1
	dic[int(s[1])] += 1
cl = []
count1 = 0
count2 = 0
count3 = 0
for x in dic.keys():
	if dic[x] == 1:
		count1 += 1
		cl.append(x)
	elif dic[x] == 2:
		count2 += 1
	else:
		count3 += 1
		p = x
if count3 == 0:
	print('Yes')
	print(1)
	print('{} {}'.format(cl[0], cl[1]))
elif count3 == 1:
	print('Yes')
	print(count1)
	for i in range(1, n + 1):
		if i != p and dic[i] == 1:
			print('{} {}'.format(p, i))
else:
	print('No')


import sys
n = int(sys.stdin.readline())
degree = [0 for i in range(n + 1)]
for i in range(n - 1):
	(u, v) = map(int, sys.stdin.readline().split())
	degree[u] += 1
	degree[v] += 1
ok = sum([int(degree[u] > 2) for u in range(n + 1)]) < 2
if not ok:
	print('No')
	sys.exit()
print('Yes')
maxdeg = max(degree)
center = degree.index(maxdeg)
ends = []
[ends.append(i) for i in range(n + 1) if degree[i] == 1]
if maxdeg == 2 or n == 2:
	print(1)
	print(ends[0], ends[1])
else:
	print(len(ends))
	[print(center, i) for i in ends]


n = int(input())
graph = [[] for i in range(n + 1)]
center = None
should_continue = True
ends = set()
for i in range(n - 1):
	parameters = [int(s) for s in input().split(' ')]
	from_ = parameters[0]
	to = parameters[1]
	graph[from_].append(to)
	graph[to].append(from_)
	if len(graph[from_]) > 2:
		if center and center != from_:
			should_continue = False
			break
		center = from_
	if len(graph[to]) > 2:
		if center and center != to:
			should_continue = False
			break
		center = to
	if len(graph[from_]) == 1:
		ends.add(from_)
	else:
		ends.discard(from_)
	if len(graph[to]) == 1:
		ends.add(to)
	else:
		ends.discard(to)
if not should_continue:
	print('No')
else:
	print('Yes')
	if center == None:
		print('1')
		print(str(ends.pop()) + ' ' + str(ends.pop()))
	else:
		print(len(graph[center]))
		for i in ends:
			print(str(center) + ' ' + str(i))