luogu#P9620. 歌姬

歌姬

Background

Are you satisfied with this?

Have you never thought about making it happen?

Made for you, made for you.

The poor system turns into a gentle duty.

Problem Description

Right now, *26 has nn matters in mind, and they form a tree. Each matter has two states: real and want. Initially, all matters are want. Assume matter 11 is the root of this tree in the mind. Then the depth of a matter uu is defined as the number of matters on the simple path from matter 11 to matter uu (including both endpoints).

We call a set of matters SS a real connected component if it satisfies: for any two real matters on the tree, all matters on the simple path between them (including endpoints) also belong to SS.
The minimal real connected component is the real connected component with the smallest number of matters.

As time goes by, the states of matters may change. Below, *26 mentions mm changes of matters to you. Each change is one of the following two types:

  1. Real u: matter uu becomes real.
  2. Want u: matter uu becomes want.

After each change, *26 will ask you: at least how many additional matters still need to be changed into want, so that the position of the matter with the minimum depth in the minimal real connected component changes, or so that there are no real matters in the mind at all.

Input Format

The first line contains two integers n,mn, m, representing the number of matters and the number of changes.

The next n1n - 1 lines each contain two integers, representing an edge of the tree.

The next mm lines are in the form Real u or Want u, representing one change. Here 1un1 \le u \le n.

Output Format

Output mm lines. Each line contains one integer, representing the answer you provide to *26 after the ii-th change.

7 8
1 2
1 5
2 3
2 4
5 6
5 7
Real 3
Real 4
Real 6
Real 7
Want 7
Real 2
Real 5
Want 3

1
1
1
2
1
1
2
2

Hint

Explanation for Sample #1

Consider the situation after the last change.

At this time, on the tree, except for matters 1,3,71,3,7 which are want, all other matters are real. Then the minimal real connected component is {1,2,4,5,6}\{1,2,4,5,6\}.

{2,4,5,6}\{2,4,5,6\} is not a minimal real connected component, because there exist two real matters such as 22 and 66, whose simple path passes through 11, but 11 is not in the set {2,4,5,6}\{2,4,5,6\}.
{1,2,3,4,5,6}\{1,2,3,4,5,6\} is also not a minimal real connected component, because there exists a real connected component {1,2,4,5,6}\{1,2,4,5,6\} whose size is smaller than it.

When we change matters 22 and 44 into want, the only real matters left are 55 and 66. Then the minimal real connected component is {5,6}\{5,6\}. The matter with the minimum depth changes from 11 to 55. It can be proven that this strategy is one of the optimal strategies.

Constraints

Test Point ID Constraints
1,21,2 1n,m201 \le n,m \le 20
3,4,53,4,5 1n,m3001 \le n,m \le 300
6,7,86,7,8 1n,m30001 \le n,m \le 3000
9,10,11,129,10,11,12 1n,m393931 \le n, m \le 39393
132013 \sim 20 1n,m2×1051 \le n, m \le 2 \times 10^5

For all testdata, it is guaranteed that at any operation, the state of the matter before the change and after the change is different.

Translated by ChatGPT 5