Logo
(追記) (追記ここまで)

18328번 - Klasika 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB37121131.429%

문제

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

  • Add x y – Adds a new node to the tree as a child of node x. The newly added node and node x are connected with an edge of weight y. 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 a and ends in some node from the subtree of node b (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.

입력

The first line contains an integer Q (1 ≤ Q ≤ 200 000) from the task description.

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

출력

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.

제한

서브태스크

번호배점제한
111

Q ≤ 200

222

Q ≤ 2 000

333

In all queries of type Query it holds b = 1

444

No additional constraints.

예제 입력 1

4
Add 1 5
Query 1 1
Add 1 7
Query 1 1

예제 출력 1

5
7

예제 입력 2

6
Add 1 5
Add 2 7
Add 1 4
Add 4 3
Query 1 1
Query 2 4

예제 출력 2

7
2

예제 입력 3

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

예제 출력 3

14
10
13

힌트

출처

Contest > Croatian Open Competition in Informatics > COCI 2019/2020 > Contest #4 4번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /