题目描述
There is a [tree] with N nodes numbered from 1 to N outside Harshikaa's house. The tree is rooted at node 1. Initially the tree was dry, there were no raindrops on any node of the tree. Suddenly it started raining, and every second a drop falls on all the leaf nodes of the tree. Also, every second any drop which wasn't already on the root node moves one node closer to the root.
Sometimes, strong winds shake the tree and all drops which were not on the root fall off. It is known that the wind will shake the tree $M times at A_{1}, A_{2}, \ldots A_{M}$ seconds after it started raining.
If multiple events happen at the same second, they are in this order:
Raindrops move one node closer to the root.
New raindrops fall on the leaves.
Wind shakes the tree.
How many drops are there at the root right after the M-th shake?
------ Input Format ------
- The first line of each input contains T - the number of test cases. The test cases then follow.
- The first line of each test case contains two space-separated integers N and M - the number of nodes on the tree and the number of shake events.
- N - 1 lines follow, each line containing two space-separated integers U and V denoting an edge between node U and V on the tree.
- The next line contains $M space-separated integers A_{1}, A_{2}, \dots, A_{M} -$ the timestamp of the shakes.
------ Output Format ------
For each test case, output in a single line the number of raindrops on the root right after the M-th shake.
------ Constraints ------
$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 100000$
$1 ≤ U, V ≤ N$
$U \neq V$
$1 ≤ M ≤ 100000$
$1 ≤ A_{i} ≤ 10^{9}$
$A$ is strictly increasing
- Sum of $N$ over all test cases is not more than $5 \cdot 10^{5}$
- Sum of $M$ over all test cases is not more than $4 \cdot 10^{5}$
----- Sample Input 1 ------
1
5 2
2 1
1 3
4 3
3 5
2 5
----- Sample Output 1 ------
5
----- explanation 1 ------
- Test case $1$: Let's define an array $R$, where $R_{i}$ is the number of raindrops on the $i$-th node.
- At second $0$, $R = [0, 0, 0, 0, 0]$.
- At second $1$, a raindrop fell on all leaves. $R$ becomes $[0, 1, 0, 1, 1]$.
- At second $2$,
- Firstly, raindrops moved closer to the root, so $R$ becomes $[1, 0, 2, 0, 0]$.
- Secondly, a raindrop fell on all leaves, so $R$ becomes $[1, 1, 2, 1, 1]$.
- Thirdly, the tree was shook, so every raindrop except the one on root fell. At the end of second $2$, $R = [1, 0, 0, 0, 0]$.
- At second $3$, new raindrops fell, and $R$ becomes $[1, 1, 0, 1, 1]$.
- At second $4$, $R$ becomes $[2, 1, 2, 1, 1]$.
- At second $5$,
- Firstly, raindrops moved closer to the root, so $R$ becomes $[5, 0, 2, 0, 0]$.
- Secondly, a raindrop fell on all leaves, so $R$ becomes $[5, 1, 2, 1, 1]$.
- Thirdly, the tree was shook, so every raindrop except the one on root fell. At the end of second $5$, $R = [5, 0, 0, 0, 0]$.
Therefore, at the end there were $5$ drops at the root.
输入格式
见题面
输出格式
见题面