QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 512 MB Toplam puan: 100

#18808. Tree and Query 5

İstatistikler

There is a tree (a connected graph with no undirected cycles) consisting of $N$ vertices. Vertices are numbered from $1$ to $N$, and edges are numbered from $1$ to $N-1$. Initially, all vertices are black.

Write a program that processes the following two types of queries:

  • 1 i: Toggle the color of vertex $i$ (white $\to$ black, black $\to$ white).
  • 2 v: Print the minimum distance from vertex $v$ to any white vertex $u$ (it is allowed that $u = v$). If $v$ itself is white, the answer is $0$. If there are no white vertices in the tree, print $-1$.

Input

The first line contains $N$ ($2 \le N \le 100{,}000$).

The next $N-1$ lines each contain two integers $u$ and $v$, the two endpoints of edge $i$.

The next line contains the number of queries $M$ ($1 \le M \le 100{,}000$).

The following $M$ lines each contain one query.

Output

For each type‑2 query, print the result on its own line, in the order they appear.

Examples

Input 1

10
1 2
1 3
2 4
1 5
1 6
4 7
7 8
5 9
1 10
10
1 6
1 6
1 6
2 3
1 1
1 1
2 3
2 10
2 4
2 6

Output 1

2
2
2
3
0

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.