#P3703. [SDOI2017] 树点涂色
[SDOI2017] 树点涂色
Description
Bob has a rooted tree with nodes, where node is the root. Bob painted each node with a color, and all nodes have pairwise distinct colors.
Define the weight of a path as the number of distinct colors among the nodes on this path (including both endpoints).
Bob may perform the following operations:
1 xRecolor all nodes on the path from to the root with a brand-new color that has never been used before.2 x yQuery the weight of the path from to .3 xWithin the subtree rooted at , choose a node so that the weight of its path to the root is maximized; output that maximum weight.
Bob will perform operations in total.
Input Format
The first line contains two integers .
The next lines each contain two integers , indicating an edge between and .
The next lines describe the operations, in the format given in the statement.
Output Format
For each operation of type 2 or 3, output one line.
For type 2, output one integer: the weight of the path.
For type 3, output one integer: the maximum weight.
5 6
1 2
2 3
3 4
3 5
2 4 5
3 3
1 4
2 4 5
1 5
2 4 5
3
4
2
2
Hint
There are 10 test points.
Test point 1: .
Test points 2 and 3: no type 2 operations.
Test points 4 and 5: no type 3 operations.
Test point 6: the tree is generated as follows — for (), randomly choose a node from to as the parent of .
Test point 7: .
Test point 8: .
Test points 9 and 10: no special restrictions.
For all testdata: , .
Translated by ChatGPT 5
京公网安备 11011102002149号