#P3348. [ZJOI2016] 大森林

[ZJOI2016] 大森林

Description

Xiao Y has a great forest at home, containing nn trees numbered from 11 to nn. Initially, each tree is just a sapling with a single node labeled 11. 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 ll-th tree to the rr-th tree each grow one child node. She can also modify the growth nodes of the ll-th tree to the rr-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 22 positive integers n,mn, m, meaning there are nn trees and mm operations.

Then follow mm 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 ll-th tree to the rr-th tree grow one child. The label of the new child equals the label generated by the previous operation of type 0 plus 11 (for example, the first operation of type 0 generates a child with label 22). The trees from ll to rr all get a child with the same label. It is guaranteed that 1lrn1 \leq l \leq r \leq n.

1 l r x Set the growth node of each tree from the ll-th to the rr-th to the node labeled xx. For the ii-th tree (lirl \leq i \leq r), if the node labeled xx is not in that tree, this operation has no effect on that tree. It is guaranteed that 1lrn1 \leq l \leq r \leq n, and xx does not exceed the current maximum label among all trees.

2 x u v Query the distance between node uu and node vv in the xx-th tree, i.e., the number of edges on the shortest path between uu and vv in the xx-th tree. It is guaranteed that 1xn1 \leq x \leq n, and nodes uu and vv 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 100%100\% of the testdata, N105,M2×105N \leq 10^5, M \leq 2 \times 10^5.

Translated by ChatGPT 5