Weak Pair
http://acm.hdu.edu.cn/showproblem.php?pid=5877
Problem Description
You are given a rooted tree of nodes, labeled from 1 to . To the ith node a non-negative value ai is assigned.An ordered pair of nodes is said to be weak if
(1) is an ancestor of (Note: In this problem a node is not considered an ancestor of itself);
(2) .
Can you find the number of weak pairs in the tree?
Input
There are multiple cases in the data set.
The first line of input contains an integer denoting number of test cases.
For each case, the first line contains two space-separated integers, and , respectively.
The second line contains space-separated integers, denoting to .
Each of the subsequent lines contains two space-separated integers defining an edge connecting nodes and , where node is the parent of node .
Constrains:
Output
For each test case, print a single integer on a single line denoting the number of weak pairs in the tree.
Sample Input
1
2 3
1 2
1 2
Sample Output
1
题目:
给你一棵有个节点的树,并且每个节点有对应的一个值,现在定义一个叫WEAK PAIR的东西(u,v),当满足一下条件是(u,v)就是WEAK PAIR:
1.u是v的祖先
2.