QOJ.ac

QOJ

时间限制: 4.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#8716. Tree

统计

The May Day holiday has arrived, and both Alice and Bob have traveled to City P. There are $n$ tourist attractions in City P, and the roads between these $n$ attractions form a tree.

In Alice's travel plan, there are $c$ target attractions. Initially, Alice appears directly at attraction $a_1$, then travels along the shortest path in City P to reach $a_2$ (she will also pass through other attractions on the shortest path), then proceeds from $a_2$ to $a_3$, and so on. Finally, after Alice reaches $a_c$, she leaves City P.

Bob has also come to City P. During the entire May Day holiday, he and Alice met at $m$ attractions, where the $i$-th meeting occurred at attraction $b_i$.

Bob wants to know the minimum number of target attractions Alice could have set during the May Day holiday, which is the minimum possible value of $c$. Bob's memory is a bit hazy, so he will modify the array $b$ multiple times. You need to provide the minimum possible $c$ after each modification.

Input

The first line contains three positive integers $n, m, q$, representing the number of nodes in the tree, the length of the sequence $b$, and the number of modifications.

The next $n-1$ lines each contain two positive integers $u_i, v_i$, describing each edge of the tree.

The next line contains $m$ positive integers representing the array $b$.

The next $q$ lines each contain two positive integers $p_i, w_i$, indicating that $b_{p_i}$ is updated to $w_i$.

$1 \le n, m, q \le 2 \times 10^5, 3 \le n$ $1 \le u_i, v_i, w_i \le n, 1 \le p_i \le m$ For any time, $\forall 1 \le i < m : b_i \neq b_{i+1}$.

Output

Output $q$ lines, each containing a positive integer representing the answer.

Examples

Input 1

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

Output 1

4
4
5

Note

For the array $b$ after the first modification in the first example, one possible shortest sequence $a$ is $[3, 5, 4, 3]$. At this time, the order in which Alice passes through the city is: $[3, 2, 1, 5, 1, 4, 1, 2, 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.