Klasika
Time limit5sMemory limit512 MB
Nodes are added as leaves to a rooted tree with XOR edge weights, and each query asks for the maximum XOR path from node a to any node in the subtree of b.
- Level
Medium7 of 10
- Topics
- Trie, Bit manipulation, Tree
- Solved
- No attempts yet
Problem
The tree starts with one node, node 1, which is the root. Process queries on this tree.
Add x y: Adds a new node as a child of node x. The new node and x are connected by an edge with weight y. The new node is numbered by the node count of the tree after the addition.Query a b: Finds the longest path that starts at node a and ends at some node in the subtree of b, with b itself included. The length of a path is the XOR of all edge weights on it.
Input
The first line contains (). Each of the next lines holds one query. The values x, a, and b always refer to existing nodes at that moment, and y is at most .
Output
For each Query, print the answer on its own line, in the order the queries appear in the input.