#P4689. [Ynoi Easy Round 2016] 这是我自己的发明
[Ynoi Easy Round 2016] 这是我自己的发明
Description
You are playing a galgame, and then your parents suddenly come in, so you pretend you are solving a data structure problem.
Given a tree with nodes. Each node has a weight. The initial root is .
There are operations of the following types:
1 x Change the root of the tree to .
2 x y Given two nodes , choose every node from the subtree of and every node from the subtree of , and count the number of pairs whose node weights are equal.
Input Format
The first line contains two integers .
The second line contains integers, where the -th integer is the node weight .
The next lines each contain two integers , indicating an edge.
The next lines each describe one operation.
Output Format
For each query, output one integer representing the answer.
5 5
1 2 3 4 5
1 2
1 3
3 4
3 5
2 4 5
2 1 5
2 3 5
1 5
2 4 5
0
1
1
1
Hint
Idea: nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477
Constraints
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号