Jumping Lights
시간 제한3초메모리 제한2048 MB
처음에는 모든 정점이 표시되지 않은 트리에서 정점을 표시하거나 해제하는 질의와, 모든 정점을 이웃에 표시된 정점이 있는지에 따라 동시에 갱신하는 질의를 처리하며 각 질의 후 표시된 정점 수를 구한다.
문제
You are given a tree: an undirected connected graph on vertices with edges. Initially, none of the vertices are marked. Your task is to process queries of the following three types:
- "
0": unmark vertex ; if is not marked, nothing happens. - "
1": mark vertex ; if is marked, nothing happens. - "
2": simultaneously for all vertices in the tree: mark the vertex if it has at least one marked neighbor, otherwise unmark it.
After each query, find how many marked vertices are there in the tree.
입력
The first line contains two integers and (; ): the number of vertices in the tree and the number of queries, respectively.
Each of the next lines describes an edge of the tree by two integers and ().
Each of the next lines represents a query in the format shown above ().
출력
Print a single line with integers: the number of marked vertices in the tree after each query.