#P7242. [COCI 2019/2020 #4] Klasika

[COCI 2019/2020 #4] Klasika

Description

At the beginning, you have a node numbered 11, which is the root of a tree. Your task is to perform QQ operations on the tree.

There are two types of operations:

  • Add x y\texttt{Add x y}: Add a child to the node numbered xx in the tree. The new node’s number is the size of the tree after adding this node, and the edge between it and xx has weight yy.
  • Query a b\texttt{Query a b}: Among all paths starting from aa to some node in the subtree of node bb (including bb), find the one with the maximum XOR sum of edge weights, and output that XOR sum.

Input Format

The first line contains an integer QQ.

The next QQ lines each contain a string and two numbers, describing one operation.

Output Format

For each Query\texttt{Query} 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
11 Q200Q \le 200 1010
22 Q2×103Q \le 2\times 10^3 2020
33 For all Query\texttt{Query} operations, b=1b = 1 is guaranteed. 3030
44 No special constraints. 4040

For 100%100\% of the testdata, 1Q2×1051 \le Q \le 2\times 10^5, 0y2300 \le y \le 2^{30}, and it is guaranteed that x,a,bx, a, b 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 110110 points.

Translated by ChatGPT 5