#P3252. [JLOI2012] 树
[JLOI2012] 树
Description
In this problem, you are given a value and a tree. Each node has a weight; the -th node has weight . Count how many paths have a total sum of node weights equal to . The depths of nodes along a path must be in strictly increasing order. Assume node is the root, its depth is , and the depth of each of its children is . A path does not have to start at the root.
Input Format
The first line contains two integers and , where is the number of nodes in the tree.
The second line contains integers; the -th integer denotes the weight of node .
The next lines each contain two integers and , indicating that is a child of .
Output Format
Output the number of paths whose total node weight equals .
3 3
1 2 3
1 2
1 3
2
Hint
Constraints
- For of the testdata, it holds that , .
Translated by ChatGPT 5
京公网安备 11011102002149号