题目描述
Alice and Bob have invented a new game. They have a rooted tree having N nodes (rooted at node 1), and the i^{th} node has the value A_{i} associated with it (1-indexed). The value associated with the root node is 0.
They start with a marker at the root node, and a score of 0. Alice and Bob moves alternatively, with Alice moving first. In one move, they can move the pointer from a node to one of its child node, and add the value associated with that child node to the score. If the marker reaches a leaf node, the game ends.
Alice wants to minimize the score of the game, whereas Bob wants to maximize the score. They were about to start the game when the Charlie arrives. He looked at the game, and declared the game to be boring. However, Charlie asked them - "What will be the score at the end of the game, if $\textbf{each}$ one of you can skip $\textbf{at most} K$ moves?"
Can you help Alice and Bob to answer Charlie?
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of testcases. The description of the T testcases follows.
- The first line of each test case contains two space separated integers N and K.
- The second line of each test case contains N space separated integers A_{1}, A_{2},..., A_{N}. It is guaranteed that A_{1} = 0.
- The following N-1 lines contains two space separated integers x and y, which denotes that there is an edge between nodes x and y.
------ Output Format ------
For each testcase, output in a single line the answer to the Charlie's problem.
------ Constraints ------
$1 ≤ T ≤ 10^{4}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 200$
$-10^{9} ≤ A_{i} ≤ 10^{9}$
$1 ≤ x, y ≤ N$
- The sum of $N$ over all test cases does not exceed $10^{5}$
----- Sample Input 1 ------
3
3 1
0 1 2
1 2
1 3
4 0
0 1 2 3
1 2
1 3
2 4
7 0
0 2 1 4 2 7 3
1 2
1 3
2 4
2 5
3 6
3 7
----- Sample Output 1 ------
1
2
6
----- explanation 1 ------
Test Case $1$: Alice can move the marker to node $2$, and hence making score $= 1$. If Alice skips her chance, then Bob can move the marker to node $3$, and hence making score = $2$. Therefore, Alice will not skip her chance.
Test Case $2$: If Alice moves the marker to node $2$, then Bob will move the marker to node $4$, making score = $4$. If Alice moves the marker to node $3$, the game will end, and the score will be $2$.
输入格式
见题面
输出格式
见题面