#P10959. [2015杭电多校]Deal

[2015杭电多校]Deal

Deal

Problem Description

soda has a tree with nn vertices. Each vertex has an initial color with it and the color of ii-th vertex is ii. And the vitalness of color ii is wiw_i. Initially, all the edges have no color and soda wants to color the edges by using the following operation:

  1. choose a vertex uu and a color cc that vertex uu contains
  2. choose another vertex vv and color all the edges and vertices along the shortest path from uu to vv with color cc. Note that one color will not cover another color, which means one edge and or vertex can have multiply colors. After mm such operations, soda computes the vitalness of the tree as follows:
  3. for each color ii, find the total length of edges having color ii denoting as lil_i
  4. the vitalness of the tree is i=1nlici\displaystyle \sum_{i=1}^{n}l_i \cdot c_i Help soda find a way to make vitalness of the tree as large as possible after mm such operations.

Input

There are multiple test cases. The first line of input contains an integer TT, indicating the number of test cases. For each test case: The first line contains two integers nn and mm (1n2000,1m109)(1 \le n \le 2000, 1 \le m \le 10^9), the number of vertices and the number of operations. The following n1n-1 lines describe the edges. The ii-th line contains three integer uiu_i, viv_i and cic_i (1ui,vin,1ci104)(1 \le u_i, v_i \le n, 1 \le c_i \le 10^4) indicating that there is edge between vertex uiu_i and vertex viv_i and the length is cic_i. The next line contains nn integers w1,w2,,wnw_1, w_2, \dots, w_n (1wi104)(1 \le w_i \le 10^4), where ii-th integer denotes the vitalness of ii-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