J. SubsetTree
time limit per test
6 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
5 2
1 2
1 3
2 4
2 5
0 1 0 0 0
3
2
Output
5
3
15