#P9399. 「DBOI」Round 1 人生如树
「DBOI」Round 1 人生如树
Background
Always this cool, always, always this cool
Like an adventurer, keep exploring the road to the mountaintop
— "Hustle"
Zhang Junhao looked out of the window. Zhu Zhixin walked over and sat beside him, folded a paper plane, and threw it out. He told Zhang Junhao to carry expectations for the future, move forward, and do not look back.
Just as described in Destiny, everyone’s life is a tree. It always grows in endless randomness and fate: some branches flourish, while some inevitably wither.
Problem Description
Zhu Zhixin obtained Zhang Junhao’s life tree using magic.
This is a tree with nodes, and node has weight .
Zhu Zhixin wants to observe moments of Zhang Junhao’s life:
Let the number of nodes on the current life tree be .
-
Input four integers . Let the array formed by the nodes on the simple path in order be , and the array formed by the nodes on the simple path in order be . Zhu Zhixin believes the similarity of these two segments of life is , and wants you to compute it. It is guaranteed that .
-
Input two integers . Zhu Zhixin observed another possible future of Zhang Junhao, so you need to create a new node with weight , numbered , and add an undirected edge , where . Clearly, after that, .
For two arrays , define their similarity as the maximum such that and for all , we have . Here denotes the length of array . In particular, if no such exists, then .
Input Format
The first line contains three positive integers , representing the number of nodes in the tree, the number of operations, and the Subtask index of this test point. For the samples, .
The next line contains integers. The -th integer is , the weight of node .
The next lines each contain two positive integers , indicating an undirected edge .
The next lines each describe one operation. The first integer in each line is , and the following integers specify the operation. When , it is operation 1; when , it is operation 2.
Output Format
For each operation 1, output one line containing the queried .
9 3 0
7 3 2 4 6 5 5 3 7
1 2
2 3
2 4
4 5
4 6
1 7
7 8
7 9
2 9 10
1 3 5 8 10
1 3 6 8 10
4
3
13 5 0
15 12 9 11 5 6 16 14 15 10 12 1 2
7 8
5 6
2 9
1 2
4 5
8 2
9 10
2 3
10 11
3 4
3 13
3 12
1 1 6 7 11
1 12 12 13 13
2 1 10
2 2 11
1 14 14 15 15
6
1
1
Hint
Sample Explanation
For sample 1, after the first operation, , and the tree is shown in the figure:

- For the second operation, the first path is , so . The second path is , so . Since , , , , the answer is .
- For the third operation, , . Since , , , but , the answer is .
For sample 2, the initial tree is shown in the figure:

| Subtask | Special Properties | Score | ||
|---|---|---|---|---|
| Subtask 1 | None | |||
| Subtask 2 | A & B | |||
| Subtask 3 | B | |||
| Subtask 4 | None | |||
| Subtask 5 | ||||
Special Property A: .
Special Property B: It is guaranteed that there is no operation 2.
Constraints: For of the data, , , .
Translated by ChatGPT 5