Black vertices - MarisaOJ: Marisa Online Judge

Black vertices

Time limit: 1000 ms
Memory limit: 256 MB
For a tree with $n$ vertices, where each vertex can be either white or black, initially all vertices are white. You need to perform $q$ queries, each query being a vertex $u$. Change the color of vertex $u$, i.e., change white to black and vice versa. After each query, find the minimum number of edges needed to connect all black-colored vertices. ### Input - The first line consists of two integers $n,q$. - The next $n - 1$ lines, each line contains two integers $u,v$, indicating an edge between $u$ and $v$. - The next $q$ lines, each line contains an integer $u$, a query. ### Output - After each query, print the minimum number of edges needed ### Constraints - $1 \le n,q \le 10^5$. - $1 \le u,v \le n$. ### Sample test Input ``` 5 10 3 2 2 4 2 5 4 1 4 3 2 1 1 3 3 3 1 4 ``` Output: ``` 0 2 2 3 2 1 2 1 2 2 ```