#P4069. [SDOI2016] 游戏
[SDOI2016] 游戏
Description
Alice and Bob are playing a game.
The game is played on a tree with vertices. Initially, each vertex contains exactly one number, which is .
Sometimes, Alice chooses the path from to and adds a number to every vertex on this path. For a vertex on the path, if the distance between and is , then the number Alice adds to is .
Sometimes, Bob chooses the path from to . He must first choose a vertex on this path, and then choose one number stored at that vertex.
Bob wants the chosen number to be as small as possible, but the large amount of numbers makes him dazzled. He needs your help to find the smallest number he can choose.
Input Format
The first line contains two integers , the number of vertices of the tree and the number of operations.
The next lines each contain three integers , indicating there is an edge connecting and with length .
The next lines each begin with an integer or .
If the first integer is , it denotes Alice’s operation, followed by four integers .
If the first integer is , it denotes Bob’s operation, followed by two integers .
Output Format
Each time Bob performs an operation, output one line with a single integer, representing the smallest number he can choose.
3 5
1 2 10
2 3 20
2 1 3
1 2 3 5 6
2 2 3
1 2 3 -5 -6
2 2 3
123456789123456789
6
-106
Hint
Test points 1–2: , , .
Test points 3–4: , , .
Test point 5: , , , the tree is a path.
Test points 6–7: , , .
Test point 8: , , , the tree is a path.
Test points 9–10: , , .
Test points 11–13: , , , the tree is a path.
Test points 14–20: , , .
For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号