## COCI '19 Contest 4 #4 Klasika

View as PDF

Points: 17 (partial)
Time limit: 2.0s
Memory limit: 512M

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

In the beginning there was a node denoted as and it represented the root of a tree. Your task is to support queries of the form:

• Add x y – Adds a new node to the tree as a child of node . The newly added node and node are connected with an edge of weight . The newly added node is denoted by a number equal to the number of nodes that the tree consists of after its addition.
• Query a b – Finds the longest path in a tree which starts in node and ends in some node from the subtree of node (which itself is considered to be in its own subtree). The length of the path is defined as exclusive or (xor) of weights of all edges that the path consists of.

#### Input

The first line contains an integer from the task description.

The -th of the next lines contains the -th query whose format corresponds to one of the queries from the task description. Values , and will refer to an existing node at that moment and value will not be greater than .

#### Output

You should output an answer to each query of type Query. Each answer should be printed in a separate line in the order in which corresponding queries appear in the input.

#### Scoring

In all queries of type Query it holds

#### Sample Input 1

4
Query 1 1
Query 1 1

#### Sample Output 1

5
7

#### Sample Input 2

6
Query 1 1
Query 2 4

#### Sample Output 2

7
2

#### Sample Input 3

10
Query 4 2
Query 1 3
Query 1 3
14
13