J. Tree Max Or
time limit per test
2 seconds
memory limit per test
500 megabytes
input
standard input
output
standard output
Example
Input
3
4
0 1 1 1
1 2
1 3
3 4
9
3 1 1 5 5 2 4 3 0
1 2
2 3
4 1
1 5
4 8
7 2
6 7
7 9
2
2 2
1 2
Output
3 2 3
14 7 4
-1