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

建议使用的浏览器:

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

6849:Flower

题目描述
Notice:Don't output extra spaces at the end of one line.

Koishi loves flowers, especially Subterranean Roses.

The rose tree consists of $n$ nodes and $n-1$ branches. You can imagine the structure of the tree as an undirected tree. There are $m$ roses blossom, and Koishi wants to pick some of them. The $i$-th rose contains the node $u$ if and only if the distance from $u$ to $x_i$ is equal to or smaller than $r_i$. Additionally, the $i$-th flower's value is $v_i$.

Koishi wants to maxmize the sum of values of picked roses. However, she doesn't like broken rose, so any two of her picked roses can't intersect. Two roses intersect if and only if there exists at least one node $u$ belongs to both of them.

So what's the largest sum of values of picked roses Koishi can get?
输入解释
The first line contains a positive integer $T(1\leq T\leq 500)$ representing the number of test cases.

For each test case, the first line contains two positive integers $n,m(1\leq n,m\leq 10^5)$, the number of nodes and roses.

The $i$-th line of the following $n-1$ lines contains two positive integers $u_i,v_i$,representing a branch in the tree which links node $u_i$ and $v_i$.

The $i$-th line of the following $m$ lines contains three non-negative integers $x_i,r_i,v_i(1\leq x_i\leq n,1\leq r_i,v_i\leq 10^9)$, describing the $i$-th rose.

There are at most $12$ test cases with $n+m>2000$
输出解释
For each test case, ouput one line with one non-negative integer as the largest sum of values.
输入样例
1
10 5
2 1
3 1
4 3
5 3
6 3
7 1
8 1
9 7
10 6
2 3 1
6 1 1
9 5 1
7 1 1
1 9 1
输出样例
2
来自杭电HDUOJ的附加信息
Recommend IceyWang

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

源链接: HDU-6849

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

共提交 0

通过率 --%
时间上限 内存上限
33000/15000MS(Java/Others) 524288/524288K(Java/Others)