Logo
(追記) (追記ここまで)

33379번 - Jumping Lights 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB0000.000%

문제

You are given a tree: an undirected connected graph on $n$ vertices with $n-1$ edges. Initially, none of the vertices are marked. Your task is to process $q$ queries of the following three types:

  • "0 $w$": unmark vertex $w$; if $w$ is not marked, nothing happens.
  • "1 $w$": mark vertex $w$; if $w$ 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 $n$ and $q$ (2ドル \le n \le 3 \cdot 10^5$; 1ドル \le q \le 10^6$): the number of vertices in the tree and the number of queries, respectively.

Each of the next $n-1$ lines describes an edge of the tree by two integers $u$ and $v$ (1ドル \le u, v \le n$).

Each of the next $q$ lines represents a query in the format shown above (1ドル \le w \le n$).

출력

Print a single line with $q$ integers: the number of marked vertices in the tree after each query.

제한

예제 입력 1

8 8
1 2
2 3
2 4
1 5
5 6
5 7
5 8
1 1
2
2
0 1
0 3
0 4
0 5
2

예제 출력 1

1 2 6 5 4 3 3 1

예제 입력 2

4 5
1 2
1 3
2 4
1 2
2
0 4
2
2

예제 출력 2

1 2 1 2 2

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2023 > Day 5: Moscow IPT Yolki-Palki Contest 1 J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /