#P3348. [ZJOI2016] 大森林
[ZJOI2016] 大森林
Description
Xiao Y has a great forest at home, containing trees numbered from to . Initially, each tree is just a sapling with a single node labeled . Each tree has a special node, called the growth node, which can grow a child node.
Xiao Y masters a kind of magic that can make the growth nodes of the -th tree to the -th tree each grow one child node. She can also modify the growth nodes of the -th tree to the -th tree. She told you the log of her magic operations. Can you manage her forest and answer her queries?
Input Format
The first line contains positive integers , meaning there are trees and operations.
Then follow lines. Each line contains several non-negative integers describing one operation, in one of the following formats:
0 l r Make each growth node of the -th tree to the -th tree grow one child. The label of the new child equals the label generated by the previous operation of type 0 plus (for example, the first operation of type 0 generates a child with label ). The trees from to all get a child with the same label. It is guaranteed that .
1 l r x Set the growth node of each tree from the -th to the -th to the node labeled . For the -th tree (), if the node labeled is not in that tree, this operation has no effect on that tree. It is guaranteed that , and does not exceed the current maximum label among all trees.
2 x u v Query the distance between node and node in the -th tree, i.e., the number of edges on the shortest path between and in the -th tree. It is guaranteed that , and nodes and exist in this tree.
Output Format
Output several lines. For each of Xiao Y’s queries, print the answer in order.
5 5
0 1 5
1 2 4 2
0 1 4
2 1 1 3
2 2 1 3
1
2
Hint
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号