#P4242. 树上的毒瘤
树上的毒瘤
Description
The tree has nodes connected by edges. Initially, there is one “tumor” hanging on each node, with color . Then Salamander will perform operations.
Sometimes Salamander will change the colors of all “tumors” on the simple path from one node to another.
For a given set of nodes on the tree, namely the point set , Salamander defines the weight of a node:
where denotes the number of color segments along the path from to . For example, if the colors along the path from to are , the number of segments is .
Salamander is very interested in the state of the “tumors” on the tree, so sometimes he will specify nodes as the set and ask for the weights of these nodes.
Input Format
The first line contains two positive integers , , the number of nodes in the tree and the number of operations.
The second line contains space-separated positive integers , the initial color of the “tumor” on each node.
The next lines each contain two positive integers , , indicating there is an edge connecting and .
Then follow operations:
- If the first integer is , then there will be three positive integers , , , meaning that all “tumor” colors on the simple path from node to node are changed to .
- If the first integer is , then there will be one positive integer , the number of specified nodes on the tree. The next line contains distinct positive integers separated by spaces, representing the nodes in the current query.
Output Format
Output several lines. For each operation of type , output the corresponding answer.
10 10
708916891 100649777 100649777 544409200 100649777 47435517 47435517 708916891 644811607 544409200
3 2
7 1
8 1
1 10
3 4
1 5
9 2
1 2
3 6
2 1
6
2 6
8 10 9 3 2 4
2 2
7 8
2 1
5
2 2
6 10
2 3
6 1 4
2 1
7
1 9 8 100649777
1 7 9 544409200
2 4
10 9 1 2
1
13 17 15 11 11 15
3 3
1
5 5
7 7 7
1
4 4 4 4
Hint
The input is guaranteed to be valid.
For of the testdata, , .
For of the testdata, , .
For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号