#P7636. [2018年杭电多校]Rikka with Treasure
[2018年杭电多校]Rikka with Treasure
Rikka with Treasure
Problem Description
By coincidentally, Rikka found a treasure map. She wants to employ several expedition teams to help her find the treasure. There are caves in the treasure maps and undirected roads between the caves. For each cave pair , it is guaranteed that there is exactly one simple path between them, and the distance between these two caves is defined by the number of caves in this path. For example, in the following treasure map, and .
Some of the caves have depots near them. Each expedition team can explore all the caves on the path (, )( may be equal to ) which satisfies there are depots near , , and are stipulated by Rikka. After the exploration, Rikka needs to pay dollars to this team. Each cave has treasure in it and the treasure in the th cave worths dollars. Rikka can get th treasure if and only if there are at least one expedition teams which have explored th cave. For example, in the previous treasure map, if , all caves have depots near them, Rikka employs two expedition teams and the first team explores path , the second team explores , then Rikka need pay dollars to the first team, dollars to the second team, and Rikka can get treasure . So the Rikka's income will be dollars. Now, for each from to , Rikka wants to calculate the maximum possible income she can get if she employs at most expedition teams.
Input
The first line contains a single integer , the number of the testcases. For each testcase, the first line contains three integers . The second line contains 01 integers . if and only if there is a depot near the th cave. The third line contains integers , which describes the value of the treasure. Then lines follow, each line contains two integers , which describes one road in the map. The input guarantees that there are at least one depots and there are at most testcases with .
Output
For each testcase, output a single line with a integers, the maximum possible income Rikka can get if she employs at most expedition teams.
Sample Input
5
5 1
1 0 1 0 1
1 2 3 4 5
1 2
2 3
2 5
3 4
5 1
1 0 1 1 1
1 2 3 4 5
1 2
2 3
2 5
3 4
5 1
1 1 1 1 1
1 2 3 4 5
1 2
2 3
2 5
3 4
5 2
1 0 1 0 1
1 2 3 4 5
1 2
2 3
2 5
3 4
5 1
1 1 1 1 1
1 2 3 4 5
1 2
1 3
1 4
1 5
Sample Output
7 7 7 7 7
10 10 10 10 10
10 10 10 10 10
4 4 4 4 4
7 9 10 10 10
Source
2018 Multi-University Training Contest 9