305152: CF981C. Useful Decomposition
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Useful Decomposition
题意翻译
### 【题目大意】: `Ramesses`了解了很多跟树(就是`OI`里的树)相关的知识。 现在,`Ramesses`发明了一种树的分解,不过他还不知道如何去分解一棵树,所以您需要帮他分解。 所谓`树的分解`,就是把树分解成好几条链,使得每条边都**在且仅在**一条链上,而且任意两条链都有**至少一个**公共点。 请您帮助`Ramesses`,找到一种可行的`树的分解`或确定无解。 ------------------------------- ### 【输入输出格式】: #### 【输入格式】: 第一行,只有一个整数$n(2\leq n\leq 1\times 10^5)$,表示这棵树的节点个数。 第$2$到第$n+1$行,每行两个整数$u,v$,表示树上有一条边,直接链接点$(u,v)$。 **输入保证无误(即输入一定是一棵树)。** -------------------------------------- #### 【输出格式】: 如果无解,则输出`No`,程序输出完毕。 如果有解,先输出一行`Yes`。然后在第$2$行中输出一个整数$m$,表示您把输入的树划分成了$m$条链。 接下来$m$行,输出两个整数$u_i,v_i(1 \leq u_i,v_i \leq n,u_i \neq v_i)$,表示每条链的起点和终点。 任意两对输出应该有**至少一个**公共点,树中的**每一条边都应该包含在输出中**,注意,**不能有两条链同时包括一条边!** 如果有多组解,输出任意一组即可(所以本题有`SPJ`)!!! ------------------------------------- ### 【样例解释】: 如图,每条边上的数字$T$代表该边被划分到第$T$条链上。第$2$组样例无解。 ---------------------------- ```cpp Translated by HPXXZYY! ```题目描述
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 \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.
输出格式
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.
输入输出样例
输入样例 #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