#P6157. 有趣的游戏
有趣的游戏
Description
The game is played on a tree of size . Each node has a weight, and the weight of node is .
Each time, the system provides a path. Xiao A can pick two nodes on this path with different weights. His score is . Then Xiao B will pick two nodes from the entire tree that Xiao A has not picked before, and the scoring method is the same as Xiao A's.
To keep the game challenging, the system sometimes increases the weight of a node.
Of course, Xiao A will try his best to maximize his score, and he wants to know what this maximum value is. At the same time, he also wants to know, when his own score is maximized, what Xiao B's maximum score is.
Input Format
The first line contains an integer , the number of nodes in the tree.
The next lines each contain two integers , indicating that there is an edge between and .
The next line contains integers, where the -th number is the weight of node .
The next line contains an integer .
The next lines each contain three integers .
If , increase by .
If , it means the system provides a path from to .
Output Format
For each query with , output one line with two integers , representing Xiao A's maximum score, and Xiao B's maximum score under this condition.
If Xiao A cannot pick two nodes with different weights, output only one number .
7
1 2
2 3
2 4
1 5
5 6
5 7
5 4 3 2 1 4 3
6
1 3 4
1 2 5
1 2 1
0 2 1
1 2 5
1 2 1
3 4
4 3
4 3
1 4
-1
Hint
Explanation of the samples:
First time: Xiao A chooses nodes and , scoring . Xiao B chooses nodes and , scoring .
Second time: Xiao A chooses nodes and , scoring . Xiao B chooses nodes and , scoring .
Third time: Xiao A chooses nodes and , scoring . Xiao B chooses nodes and , scoring .
Fourth time: the weight of node becomes .
Fifth time: Xiao A chooses nodes and , scoring . Xiao B chooses nodes and , scoring .
Sixth time: the only nodes Xiao A can choose are , and both have weight , so there is no valid choice.
This problem uses bundled testdata.
| Subtasks | Special Properties | Score | |
|---|---|---|---|
| Subtask1 | None | ||
| Subtask2 | Tree shape, node weights are random | ||
| Subtask3 | At most different node weights, and no modifications | ||
| Subtask4 | The tree is a chain, and for node its parent is | ||
| Subtask5 | None |
Constraints: for all data, , , the added value is a positive integer not greater than , and the input is a valid tree. It is guaranteed that at any time, the number of distinct values is at least .
Translated by ChatGPT 5
京公网安备 11011102002149号