QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 512 MB مجموع النقاط: 100

#18809. 트리와 쿼리 6

الإحصائيات

$N$개의 정점으로 이루어진 트리(무방향 사이클이 없는 연결 그래프)가 있다. 정점은 $1$번부터 $N$번까지 번호가 매겨져 있고, 간선은 $1$번부터 $N-1$번까지 번호가 매겨져 있다. 가장 처음에 모든 정점의 색은 검정색이다.

아래의 두 쿼리를 수행하는 프로그램을 작성하시오.

  • 1 i: $i$번 정점의 색을 바꾼다. (흰색 $\to$ 검정색, 검정색 $\to$ 흰색)
  • 2 u: $u$와 연결된 정점 $v$의 개수를 센다. 두 정점이 연결되었다는 것은 두 정점을 연결하는 경로상의 모든 정점의 색이 같다는 것을 의미한다.

입력

첫째 줄에 $N$ ($2 \le N \le 100{,}000$)이 주어진다.

둘째 줄부터 $N-1$개의 줄에는 $i$번 간선이 연결하는 두 정점 번호 $u$와 $v$가 주어진다.

다음 줄에는 쿼리의 개수 $M$ ($1 \le M \le 100{,}000$)이 주어진다.

다음 $M$개의 줄에는 쿼리가 한 줄에 하나씩 주어진다.

출력

각각의 2번 쿼리의 결과를 순서대로 한 줄에 하나씩 출력한다.

Sample

Input

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

Output

5
1

Sample

Input

7
1 2
1 3
2 4
2 5
3 6
3 7
4
2 1
1 1
2 2
2 3

Output

7
3
3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.