CF981C.Useful Decomposition
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
输入格式
The first line contains a single integer n ( 2≤n≤105 ) the number of nodes in the tree.
Each of the next n − 1 lines contains two integers ai and bi ( 1≤ai,bi≤n , ai=bi ) — the edges of the tree. It is guaranteed that the given edges form a tree.
输出格式
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 ui , vi ( 1≤ui,vi≤n , ui=vi ) denoting that one of the paths in the decomposition is the simple path between nodes ui and vi .
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.
输入输出样例
输入#1
4 1 2 2 3 3 4
输出#1
Yes 1 1 4
输入#2
6 1 2 2 3 3 4 2 5 3 6
输出#2
No
输入#3
5 1 2 1 3 1 4 1 5
输出#3
Yes 4 1 2 1 3 1 4 1 5
说明/提示
The tree from the first example is shown on the picture below: 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: We can show that there are no valid decompositions of this tree.
The tree from the third example is shown on the picture below: 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.