Pro.ID22149 TitleTree Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22149 AC1 Submit2 Ratio50.00% 时间&空间限制描述In this problem, you are given a value S, and a tree. There is a positive integer in each node of the tree. You are asked how many pathes are there which sum up to S. The depth of nodes in the path must be in increasing order. We assume node 1 is the root. The depth of the root is 0, and its children's depth is 1, etc. The path doesn't have to be from the root. 输入The first line contains two integers N and S, where N ( 1 ≤ N ≤ 1000000 ) is the number of nodes in the tree. The next line contains N positive integers, the i-th integer is in node i. Then the next N-1 line each contains two integer x, y, meaning that y is the child of x. 输出Description In this problem, you are given a value S, and a tree. There is a positive integer in each node of the tree. You are asked how many pathes are there which sum up to S. The depth of nodes in the path must be in increasing order. We assume node 1 is the root. The depth of the root is 0, and its children's depth is 1, etc. The path doesn't have to be from the root. Input The first line contains two integers N and S, where N ( 1 ≤ N ≤ 1000000 ) is the number of nodes in the tree. The next line contains N positive integers, the i-th integer is in node i. Then the next N-1 line each contains two integer x, y, meaning that y is the child of x. Output Just output in a single line the number of paths which sum up to S. Sample Input 3 3 Sample Output 2 Source 样例输入3 3 样例输出2 作者 |