当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5356:Deal

题目描述
soda has a tree with $n$ vertices. Each vertex has an initial color with it and the color of $i$-th vertex is $i$. And the vitalness of color $i$ is $w_i$. Initially, all the edges have no color and soda wants to color the edges by using the following operation:
1. choose a vertex $u$ and a color $c$ that vertex $u$ contains
2. choose another vertex $v$ and color all the edges and vertices along the shortest path from $u$ to $v$ with color $c$.

Note that one color will not cover another color, which means one edge and or vertex can have multiply colors.

After $m$ such operations, soda computes the vitalness of the tree as follows:
1. for each color $i$, find the total length of edges having color $i$ denoting as $l_i$
2. the vitalness of the tree is $\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 $m$ such operations.
输入解释
There are multiple test cases. The first line of input contains an integer $T$, indicating the number of test cases. For each test case:

The first line contains two integers $n$ and $m$ $(1 \le n \le 2000, 1 \le m \le 10^9)$, the number of vertices and the number of operations.
The following $n-1$ lines describe the edges. The $i$-th line contains three integer $u_i$, $v_i$ and $c_i$ $(1 \le u_i, v_i \le n, 1 \le c_i \le 10^4)$ indicating that there is edge between vertex $u_i$ and vertex $v_i$ and the length is $c_i$.
The next line contains $n$ integers $w_1, w_2, \dots, w_n$ $(1 \le w_i \le 10^4)$, where $i$-th integer denotes the vitalness of $i$-th color.
输出解释
For each case, output an integer denoting the maximum vitalness soda can get.
输入样例
2
3 2
1 2 1
2 3 2
1 10 100
2 100
1 2 1
1 1
输出样例
320
2
来自杭电HDUOJ的附加信息
Author zimpha@zju
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5356

最后修改于 2020-10-25T23:21:58+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000/2500MS(Java/Others) 131072/131072K(Java/Others)