Whoa! You did a great job helping Team Rocket who managed to capture all the Pokemons sent by Bash. Meowth, part of Team Rocket, having already mastered the human language, now wants to become a master in programming as well. He agrees to free the Pokemons if Bash can answer his questions.
Initially, Meowth gives Bash a weighted tree containing
The first line contains two integers
The next line contains
Each of the next
Each query consists of one line. The first integer is
For each query of type
Subtask # | Score | Constraints |
---|---|---|
1 | 8 | |
2 | 15 | |
3 | 20 | All queries are of type |
4 | 21 | All queries are of type |
5 | 36 | No additional constraints |
Sample Input 1 | Sample Output 1 |
5 5
|
23
|
Subtask | Score |
---|---|
1 | 8 |
2 | 15 |
3 | 20 |
4 | 21 |
5 | 36 |
6 | 0 |
7 | 0 |