AdvancedRating 1700
Root-to-Node Paths With Sum k
The tree is rooted at node 1. Count the downward paths (from a node to one of its descendants, or a single node) whose values add up to k.
Input
n and k; the n values; then n − 1 lines 'u v'.
Output
One integer.
Sample 1
Input
5 3 1 2 1 3 -1 1 2 1 3 2 4 3 5
Output
2
Sample 2
Input
1 5 5
Output
1
Output appears here