#P10959. [2015杭电多校]Deal
[2015杭电多校]Deal
Deal
Problem Description
soda has a tree with vertices. Each vertex has an initial color with it and the color of -th vertex is . And the vitalness of color is . Initially, all the edges have no color and soda wants to color the edges by using the following operation:
- choose a vertex and a color that vertex contains
- choose another vertex and color all the edges and vertices along the shortest path from to with color . Note that one color will not cover another color, which means one edge and or vertex can have multiply colors. After such operations, soda computes the vitalness of the tree as follows:
- for each color , find the total length of edges having color denoting as
- the vitalness of the tree is Help soda find a way to make vitalness of the tree as large as possible after such operations.
Input
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case: The first line contains two integers and , the number of vertices and the number of operations. The following lines describe the edges. The -th line contains three integer , and indicating that there is edge between vertex and vertex and the length is . The next line contains integers , where -th integer denotes the vitalness of -th color.
Output
For each case, output an integer denoting the maximum vitalness soda can get.
Sample Input
2
3 2
1 2 1
2 3 2
1 10 100
2 100
1 2 1
1 1
Sample Output
320
2
Author
zimpha@zju
Source
2015 Multi-University Training Contest 6