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 matters in mind, and they form a tree. Each matter has two states: real and want. Initially, all matters are want. Assume matter is the root of this tree in the mind. Then the depth of a matter is defined as the number of matters on the simple path from matter to matter (including both endpoints).
We call a set of matters 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 .
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 changes of matters to you. Each change is one of the following two types:
Real u: matter becomes real.Want u: matter 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 , representing the number of matters and the number of changes.
The next lines each contain two integers, representing an edge of the tree.
The next lines are in the form Real u or Want u, representing one change. Here .
Output Format
Output lines. Each line contains one integer, representing the answer you provide to *26 after the -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 which are want, all other matters are real. Then the minimal real connected component is .
is not a minimal real connected component, because there exist two real matters such as and , whose simple path passes through , but is not in the set .
is also not a minimal real connected component, because there exists a real connected component whose size is smaller than it.
When we change matters and into want, the only real matters left are and . Then the minimal real connected component is . The matter with the minimum depth changes from to . It can be proven that this strategy is one of the optimal strategies.
Constraints
| Test Point ID | Constraints |
|---|---|
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