#P3302. [SDOI2013] 森林
[SDOI2013] 森林
Description
Xiao Z has a forest with nodes, and each node has a non-negative integer as its weight. Initially, there are edges in the forest.
Xiao Z wants to perform operations of two types:
Q x y kQuery the -th smallest weight among all the weights on the path from to . It is guaranteed that and are connected, and there are at least nodes on this path.L x yAdd an edge between nodes and . It is guaranteed that after this operation, the graph is still a forest.
To make the program online, the input is encrypted. Let be the last printed answer, initially .
For an input operation Q x y k, the real operation is Q x^lastans y^lastans k^lastans.
For an input operation L x y, the real operation is L x^lastans y^lastans. Here the operator ^ denotes bitwise XOR, equivalent to xor in Pascal.
Please write a program to help Xiao Z finish these operations.
Input Format
The first line contains a positive integer , indicating the test point index of the current testdata.
The second line contains three integers , denoting the number of nodes, the number of initial edges, and the number of operations, respectively.
The third line contains non-negative integers, representing the weights of the nodes.
The next lines each contain two integers and , indicating that initially there is an undirected edge between and .
The next lines each describe an operation, in the format Q x y k or L x y, as defined above.
Output Format
For each operation of the first type, output a non-negative integer as the answer.
1
8 4 8
1 1 2 2 3 3 4 4
4 7
1 8
2 4
2 1
Q 8 7 3
Q 3 5 1
Q 10 0 0
L 5 4
L 3 2
L 0 7
Q 9 2 5
Q 6 1 6
2
2
1
4
2
Hint
Sample explanation:
For the first operation Q 8 7 3, at this time , so the real operation is Q 8^0 7^0 3^0, i.e., Q 8 7 3. There are nodes on the path from to , and their weights are . Among these weights, the -rd smallest is , so output , and becomes .
For the second operation Q 3 5 1, at this time , so the real operation is Q 3^2 5^2 1^2, i.e., Q 1 7 3. There are nodes on the path from to , and their weights are . Among these weights, the -rd smallest is , so output , and becomes . The subsequent operations are similar.
Constraints
| Test point index | Upper bounds of | L operations |
Q operations |
Structure |
|---|---|---|---|---|
| N/A | N/A | N/A | ||
No L operations |
Chain | |||
| Guaranteed | N/A | |||
| N/A | ||||
No L operations |
N/A | |||
| N/A | ||||
Note: N/A means no special property.
For of the testdata, all node indices are in the range . Each node’s weight . .
Translated by ChatGPT 5
京公网安备 11011102002149号