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

建议使用的浏览器:

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

6820:Tree

题目描述
Aphelios likes to play with tree. A weighted tree is an undirected connected graph without cycles and each edge has a weight. The degree of each vertex is the number of vertexes which connect with it. Now Aphelios has a weighted tree $T$ with $n$ vertex and an integer $k$, and now he wants to find a subgraph $G$ of the tree, which satisfies the following conditions:

$1$. $G$ should be a connected graph, in other words, each vertex can reach any other vertex in the subgraph $G$.

$2$. the number of the vertex whose degree is larger than $k$ is no more than $1$.

$3$. the total weight of the subgraph is as large as possiblie.

Now output the maximum total weight of the subgraph you can find.
输入解释
The first line contains an integer $q$, which represents the number of test cases.

For each test case, the first line contains two integer $n$ and $k$ $(1\leq n\leq 2 \times 10^{5},0\leq k<n)$.

For next $n-1$ lines , each line contains $3$ numbers $u,v,d$, which means that there is an edge between $u$ and $v$ weighted $d$ $(1\leq u,v\leq n,0\leq d \leq 10^{9})$.

You may assume that $\sum n \leq 10^{6}$.
输出解释
For each test case, output one line containing a single integer $ans$ denoting the total weight of the subgraph.
输入样例
1
5 2
1 2 5
2 3 2
2 4 3
2 5 4
输出样例
14
来自杭电HDUOJ的附加信息
Recommend IceyWang

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

源链接: HDU-6820

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

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 262144/262144K(Java/Others)