QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 256 MB مجموع النقاط: 100 قابلة للهجوم ✓

#18324. Lele's Apricot Blossoms

الإحصائيات

Lele wants to see apricot blossoms and is always on the road to see them.

Lele is always on the road to see apricot blossoms, but the world is too big and the flowering period of apricot blossoms is too short. At some moment, the apricot blossoms in a certain place bloom, and at another moment, they fall. Lele knows that always heading towards the nearest apricot blossoms does not guarantee she will arrive before they fall, so she decides to use a dice to decide which path to take.

However, she always wants to know how far away the nearest blooming apricot blossoms are.

The world map is summarized by Lele as a connected graph with $n$ nodes and $n-1$ edges, where each node has an apricot tree. After finishing her complex dynamic out-of-order multi-issue processor, Lele decides to spend $m$ units of time searching for apricot blossoms. That is to say, within $m$ units of time, one of the following three events will occur at each unit of time:

  • Apricot blossoms in a certain place bloom.
  • Apricot blossoms in a certain place fall.
  • Lele moves to a node adjacent to her current node.

Lele is initially at node 1.

Input

The first line contains two integers $n$ and $m$, representing the number of nodes and the time, respectively.

The next $n-1$ lines each contain two integers $x$ and $y$, representing an edge between $x$ and $y$.

The next $m$ lines each contain two integers $op$ and $x$:

  • If $op = 1$, it means the state of the apricot blossoms at node $x$ has changed. If there were blooming apricot blossoms at node $x$ before, they now wither; if there were no blooming apricot blossoms at node $x$ before, they now bloom.
  • If $op = 2$, it means Lele has moved to node $x$. It is guaranteed that node $x$ is adjacent to the node where Lele was previously located.

Output

Output $m$ lines. The $i$-th line represents the distance from Lele to the nearest blooming apricot blossoms at time $i$. If there are no blooming apricot blossoms, output "2147483648".

Examples

Input 1

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

Output 1

2147483648
0
0
1

Note

$1 \le n, m \le 10^5$, $op \in \{1, 2\}$, $1 \le x \le n$.

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.