当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5423:Rikka with Tree

题目描述
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

For a tree $T$, let $F(T,i)$ be the distance between vertice 1 and vertice $i$.(The length of each edge is 1).

Two trees $A$ and $B$ are similiar if and only if the have same number of vertices and for each $i$ meet $F(A,i)=F(B,i)$.

Two trees $A$ and $B$ are different if and only if they have different numbers of vertices or there exist an number $i$ which vertice $i$ have different fathers in tree $A$ and tree $B$ when vertice 1 is root.

Tree $A$ is special if and only if there doesn't exist an tree $B$ which $A$ and $B$ are different and $A$ and $B$ are similiar.

Now he wants to know if a tree is special.

It is too difficult for Rikka. Can you help her?
输入解释
There are no more than 100 testcases.

For each testcase, the first line contains a number $n(1 \leq n \leq 1000)$.

Then $n-1$ lines follow. Each line contains two numbers $u,v(1 \leq u,v \leq n)$ , which means there is an edge between $u$ and $v$.
输出解释
For each testcase, if the tree is special print "YES" , otherwise print "NO".
输入样例
3
1 2
2 3
4
1 2
2 3
1 4
输出样例
YES
NO

提示
For the second testcase, this tree is similiar with the given tree:
4
1 2
1 4
3 4
来自杭电HDUOJ的附加信息
Recommend hujie

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5423

最后修改于 2020-10-25T23:22:32+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)