1732.
Similarity
时间限制 3000 ms
内存限制 64 MB
There is a tree grows on both HNN and HBB's head. The two tree has the same size n and index start from 1.
As HBB's son, HNN suddenly realizes that his tree doesn't look like daddy's at all. So he can't stop crying and thinking about how hard the life is. So HBB has to remark son's tree to make it look like daddy's tree as much as possible.
We define the similarity degree of two tree's as the number of nodes whose farther has the same id in both tree. Note that root doesn't has farther node, so it can't increase the similarity degree.We define the similarity degree of two tree's as the number of nodes whose farther has the same id in both tree. For example, if node-2's farther node is node-3 in the first tree, and node-2's farther node is also node-3 in the second tree, then node-2 is such the kind of node which increase the similarity degree between the two tree.
It is a hard work to make HBB and HNN's similarity degree reach n-1(it is impossible to reach n because the root node), so if HBB can make their similarity degree reach n-3 or more, HNN will stop crying. Is it possible?
NOTE: maybe the similarity degree has already reach n-3 or more at the beginning, the answer is true of course
输入数据
输出数据
For each test case output one line denotes the answer.
If the similarity can reach n-3, output "YES" , "NO" otherwise.
样例输入
复制
1
5
1 1 3 3
1 2 1 4
\n
\n
· · · \n
· · · \n