#P3252. [JLOI2012] 树

[JLOI2012] 树

Description

In this problem, you are given a value ss and a tree. Each node has a weight; the ii-th node has weight aia_i. Count how many paths have a total sum of node weights equal to ss. The depths of nodes along a path must be in strictly increasing order. Assume node 11 is the root, its depth is 00, and the depth of each of its children is 11. A path does not have to start at the root.

Input Format

The first line contains two integers nn and ss, where nn is the number of nodes in the tree.

The second line contains nn integers; the ii-th integer aia_i denotes the weight of node ii.

The next n1n - 1 lines each contain two integers xx and yy, indicating that yy is a child of xx.

Output Format

Output the number of paths whose total node weight equals ss.

3 3
1 2 3
1 2
1 3
2

Hint

Constraints

  • For 100%100\% of the testdata, it holds that 1n1051 \leq n \leq 10^5, 1ai,s1031 \leq a_i, s \leq 10^3.

Translated by ChatGPT 5