C. Useful Decomposition
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nn (2≤n≤1052≤n≤105) the number of nodes in the tree.

Each of the next n−1n − 1 lines contains two integers aiai and bibi (1≤ai,bi≤n1≤ai,bi≤n, ai≠biai≠bi) — 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 mm.

Each of the next mm lines should contain two integers uiui, vivi (1≤ui,vi≤n1≤ui,vi≤n, ui≠viui≠vi) denoting that one of the paths in the decomposition is the simple path between nodes uiui and vivi.

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

Copy
4
1 2
2 3
3 4
output

Copy
Yes
1
1 4
input

Copy
6
1 2
2 3
3 4
2 5
3 6
output

Copy
No
input

Copy
5
1 2
1 3
1 4
1 5
output

Copy
Yes
4
1 2
1 3
1 4
1 5
Note

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.

题意  分成任意条路   任意两条路至少有一个交点     而且任意两条路不能有相同的边  输出 路径

解析  可以得到  所有路只有一个交点  所以最多只有一个点的度数大于等于3 才有解决方案 那个点就是交点  以它为起点枚举路径就好了

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=,maxn=1e5+;
#define ios() ios::sync_with_stdio(false),cin.tie(),cout.tie()
vector<int> g[maxn];
int vis[maxn],ans[maxn],cnt;
void dfs(int x)
{
vis[x]=;
int flagg=;
for(int i=;i<g[x].size();i++)
{
int u=g[x][i];
if(vis[u]==)
{
flagg++;
dfs(u);
}
}
if(flagg==)
ans[cnt++]=x;
}
int main()
{
ios();
int n;
cin>>n;
for(int i=;i<n-;i++)
{
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
int flag=,sum=;
for(int i=;i<=n;i++)
{
if(g[i].size()>=)
sum++,flag=i;
}
if(sum>=)
cout<<"No"<<endl;
else
{
memset(vis,,sizeof(vis));
cnt=;
dfs(flag);
cout<<"Yes"<<'\n'<<cnt<<endl;
for(int i=;i<cnt;i++)
{
cout<<flag<<" "<<ans[i]<<endl;
}
}
}

Avito Code Challenge 2018 C的更多相关文章

  1. Codeforces Avito Code Challenge 2018 D. Bookshelves

    Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...

  2. Codeforces - Avito Code Challenge 2018

    Portal A. Antipalindrome 暴力. B. Businessmen Problems 暴力. C. Useful Decomposition 居然不是C打头的?! 将一棵树划分成若 ...

  3. cf掉分记——Avito Code Challenge 2018

    再次作死的打了一次cf的修仙比赛感觉有点迷.. 还好掉的分不多(原本就太低没法掉了QAQ) 把会做的前三道水题记录在这.. A: Antipalindrome emmmm...直接暴力枚举 code: ...

  4. Avito Code Challenge 2018

    第一次打CF,很菜,A了三道水题,第四题好像是是数位DP,直接放弃了.rateing从初始的1500变成了1499,还是绿名,这就很尴尬.之后觉得后面的题目也没有想象的那么难(看通过人数)过两天吧剩下 ...

  5. Avito Code Challenge 2018 A~E

    A. Antipalindrome 还以为是什么神dp结果就是分情况讨论啊 原串是一串一样的字符的话输出0,是回文串的话输出n-1,否则直接输出原串长度 #include<iostream> ...

  6. [Avito Code Challenge 2018 G] Magic multisets(线段树)

    题目链接:http://codeforces.com/contest/981/problem/G 题目大意: 有n个初始为空的‘魔法’可重集,向一个‘可重集’加入元素时,若该元素未出现过,则将其加入: ...

  7. Avito Cool Challenge 2018 E. Missing Numbers 【枚举】

    传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds me ...

  8. Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】

    传送门:http://codeforces.com/contest/1081/problem/C C. Colorful Bricks time limit per test 2 seconds me ...

  9. Avito Cool Challenge 2018 B. Farewell Party 【YY】

    传送门:http://codeforces.com/contest/1081/problem/B B. Farewell Party time limit per test 1 second memo ...

随机推荐

  1. AJPFX总结关于JVM的基础知识

    写在前面 之前老大让做一些外包面试,我的问题很简单: 介绍一下工作中解决过比较 有意思的问题. HashMap使用中需要注意的点. 第一个问题主要是想了解一下对方项目经验的含金量,第二个问题则是测试下 ...

  2. SpringBoot 2.x (4):配置文件与单元测试

    SpringBoot的配置文件有默认的application.properties 还可以使用YAML 区别: application.properties示例: server.port=8090 s ...

  3. [BZOJ2002][Hnoi2010]Bounce弹飞绵羊 LCT

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 建图,每次往后面跳就往目标位置连边,将跳出界的点设为同一个点.对于修改操作发现可以用 ...

  4. 12 DOM操作应用

    1.创建子元素oLi=document.creatElement('li') 2.将元素附给父级元素oUl.appendChild(oLi) 3.将元素插入到父级元素里的第一位子元素之前oUl.ins ...

  5. react学习文档

    转自http://www.ruanyifeng.com/blog/2015/03/react.html,阮一峰老师的博客. 最近想学习react,官方文档的例子不是那么浅显易懂,看了相关博客,觉得阮一 ...

  6. core\stm32f10x.h(244): error: #67: expected a "}"

  7. git 恢复误删的文件

    误删的文件如何恢复呢? 执行下面的命令: 1. git reset HEAD a.txt 2. git checkout a.txt 注意:上面两个命令,可以帮我们找回删除的文件,但是对文件内容的修改 ...

  8. ijkplayer seekTo回跳以前从指定位置播放解决办法

    相信在使用ijkplayer播放视频时候,大部分情况会遇到SEEKTO的问题,就是拖动后,不会从拖动结束的位置播放,而是大部分拖动后,会回跳一段时间,甚至从头开始播放. 官方称这 是正常的,因为视频拖 ...

  9. matlab遗传算法工具箱

    转自http://blog.sina.com.cn/s/blog_5ebcc0240101pnrj.html matlab遗传算法工具箱函数及实例讲解 (2014-01-10 13:03:57)   ...

  10. Beta冲刺提交-星期三

    - 这个作业属于哪个课程 <https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1> 这个作业要求在哪里 <htt ...