| Codeforces Round 1138 (Div. 3) |
|---|
| Finished |
In one of their old photos, Aubrey spotted Sunny holding a paper cup to his ear. A string stretched from the cup and out of the picture. She remembered the day they had built a whole phone network out of paper cups and string.
There were $$$n$$$ friends playing that day, including Sunny and Aubrey. The phone lines between them formed a tree. At the start of the game, each friend knew exactly one piece of news. No two friends had the same news.
Sunny kept a list of all $$$m$$$ calls in the order they took place. During each call, the two friends at opposite ends of the line told each other everything they knew. They remembered every piece of news they heard. The same line could be used more than once.
That evening, Aubrey wrote down how many different pieces of news each friend knew and added up the numbers. Let $$$S$$$ be this sum. For example, a piece of news known to three friends counts three times.
Help Sunny and Aubrey find, for each call, how much smaller $$$S$$$ would have been if that call had been missed. Consider each call independently. All the other calls take place in their original order.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 4\cdot 10^5$$$, $$$1 \le m \le 4\cdot 10^5$$$) — the number of friends and the number of calls.
For $$$1 \le i \lt n$$$, the $$$i$$$-th of the next $$$n-1$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i,v_i \le n$$$, $$$u_i \ne v_i$$$). Phone line $$$i$$$ connects friends $$$u_i$$$ and $$$v_i$$$. These lines form an undirected tree.
The last line of each test case contains $$$m$$$ integers $$$e_1,e_2,\ldots,e_m$$$ ($$$1 \le e_i \lt n$$$). Call $$$i$$$ uses phone line $$$e_i$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$4\cdot 10^5$$$. It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$4\cdot 10^5$$$.
For each test case, print $$$m$$$ integers. The $$$i$$$-th integer is the difference between $$$S$$$ with all calls and $$$S$$$ with only call $$$i$$$ missed.
44 41 22 33 41 2 3 24 41 22 33 41 2 2 32 11 213 32 13 21 1 1
4 2 5 14 0 0 420 0 0
In the first test case, the four friends finish the day knowing $$$2,4,4,4$$$ pieces of news, respectively. If the first call is missed, they finish with $$$1,3,3,3$$$. The first answer is $$$14-10=4$$$.
In the second test case, friends $$$2$$$ and $$$3$$$ call each other twice in a row. Missing either one of these calls leaves the final counts unchanged.
| Name |
|---|


