Rank 161 the next year: the course of four solutions has three exams! Last year's rank…
- User
Rank 161 the next year: the course of four solutions has three exams!
Last year's rank one: Ah! Ah! So let 160 be your rank!
Congratulations! You have become the cake-distributor of the exam session! You have to do something to solve the lovely threes! Third-party solutions use advanced cheating methods! One of these methods is the cheat tree! In this way, each person corresponds to a vertex!
You have been asked by Hali Sey (!) to do the following for easier cheating!
First of all, we have a head as the headquarters (with number 1) who has been at his seat since last night. Each time we do one of these two things:
1 p: According to the program, a triple solution is entered! If before the arrival of this person k k people were present at the meeting, we no k + 1 We assign k+1 to that individual and assign it to the vertex of the number p We connect p.
d v 2: the farthest vertex from the command headquarters, with v v max d We find d distance edge and report it!
As it is known. A graph always remains a tree.
input In the first line of the input q q number of queries. then q q lines are each as described. 1 ≤ q ≤ 200
000 1≤q≤200 000 0 ≤ d ≤ 1
000
000
000 0≤d≤1 000 000 000 Queries are guaranteed p p and v v are present in the graph.
output For each type two query, print the answer.
If there are several correct answers, print one of them as desired.
Example Sample entry 1 5 1 1 1 1 2 2 10 1 3 2 2 10 Plain text Sample output 1 2 4 Plain text Sample entry 2 9 1 1 1 1 1 2 2 3 3 1 4 2 3 4 1 4 1 6 2 4 2 Plain text Sample output 2 4 5 7
- Assistant
- User
c++
- Assistant