#P7394. 「TOCO Round 1」History

「TOCO Round 1」History

Description

There is a tree with nn nodes, rooted at node 11. Each node has a lamp, and all lamps are initially off. Now mm events occur, in the following forms:

1 x Toggle the lamp at node xx (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 xx and have distance yy from node xx in the tree.

3 x Revert to the state right after the xx-th event.

For each query of type 22, output the answer.

Input Format

The first line contains an integer nn.
The next n1n-1 lines each contain two integers u,vu, v, indicating an edge between uu and vv.
Then an integer mm follows. The next mm lines each contain two or three integers describing an event.

Output Format

For each query of type 22, 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, ymod2=1y \bmod 2 = 1.

  • Subtask 2 (20 pts): n,m10n, m \leq 10.

  • Subtask 3 (30 pts): n,m103n, m \leq 10^3.

  • Subtask 4 (40 pts): n,m105n, m \leq 10^5.

For 100%100\% of the testdata, 1n,m1051 \leq n, m \leq 10^5, and operations of type 33 guarantee 0x0 \leq x.

Translated by ChatGPT 5