#P7394. 「TOCO Round 1」History
「TOCO Round 1」History
Description
There is a tree with nodes, rooted at node . Each node has a lamp, and all lamps are initially off. Now events occur, in the following forms:
1 x Toggle the lamp at node (turn it off if it is on, otherwise turn it on).
2 x y Query the number of nodes whose lamps are on among the nodes that are at the same depth as node and have distance from node in the tree.
3 x Revert to the state right after the -th event.
For each query of type , output the answer.
Input Format
The first line contains an integer .
The next lines each contain two integers , indicating an edge between and .
Then an integer follows. The next lines each contain two or three integers describing an event.
Output Format
For each query of type , output the answer.
3
1 2
1 3
6
1 3
2 2 2
1 2
2 2 2
1 3
2 2 2
1
1
0
Hint
This problem uses bundled evaluation.
-
Subtask 1 (10 pts): For all queries, .
-
Subtask 2 (20 pts): .
-
Subtask 3 (30 pts): .
-
Subtask 4 (40 pts): .
For of the testdata, , and operations of type guarantee .
Translated by ChatGPT 5
京公网安备 11011102002149号