#P7242. [COCI 2019/2020 #4] Klasika
[COCI 2019/2020 #4] Klasika
Description
At the beginning, you have a node numbered , which is the root of a tree. Your task is to perform operations on the tree.
There are two types of operations:
- : Add a child to the node numbered in the tree. The new node’s number is the size of the tree after adding this node, and the edge between it and has weight .
- : Among all paths starting from to some node in the subtree of node (including ), find the one with the maximum XOR sum of edge weights, and output that XOR sum.
Input Format
The first line contains an integer .
The next lines each contain a string and two numbers, describing one operation.
Output Format
For each operation, output one integer per line representing the answer.
4
Add 1 5
Query 1 1
Add 1 7
Query 1 1
5
7
6
Add 1 5
Add 2 7
Add 1 4
Add 4 3
Query 1 1
Query 2 4
7
2
10
Add 1 4
Add 1 9
Add 1 10
Add 2 2
Add 3 3
Add 4 4
Query 4 2
Query 1 3
Add 6 7
Query 1 3
14
10
13
Hint
【Constraints and Rules】
| Subtask ID | Special Constraints | Score |
|---|---|---|
| For all operations, is guaranteed. | ||
| No special constraints. |
For of the testdata, , , and it is guaranteed that are less than or equal to the current size of the tree.
【Hints and Help】
This problem is translated from COCI 2019/2020 CONTEST #4 T4 Klasika.
In COCI, this problem is worth points.
Translated by ChatGPT 5
京公网安备 11011102002149号