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

建议使用的浏览器:

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

6634:Salty Fish

题目描述
Little Q has an apple tree with $n$ nodes, labeled by $1,2,\dots,n$. The root of the tree is the $1$-th node and the length of each edge is one unit. There are $a_i$ apples on the $i$-th node. The price of each apple is one dollar, so if you sell $t$ apples, you will gain $t$ dollars.

Skywalkert, a close friend of Little Q, lost most of his money betting on programming contests, so he wants to steal some apples from this apple tree and sell them to make money.

The security system takes pictures of the nodes once per hour using $m$ cameras. Let's denote $d(x,y)$ as the number of edges on the shortest path from the $x$-th node to the $y$-th node, and denote set $p(x,k)$ as $\{y|\texttt{y in x's subtree and } d(x,y)\leq k\}$. Note that $x\in p(x,k)$. The image from the $i$-th camera shows the picture of all the nodes in $p(x_i,k_i)$. If the security system detects a change in any of these images, it sounds an alarm, the thief will be caught by Little Q.

Skywalkert is also a gifted hacker. He can lock some cameras so that images from these cameras will never change. Specifically, if he want to lock the $i$-th camera, he needs to pay $c_i$ dollars to do such a hack.

Please write a program to help Skywalkert make money optimally without being caught.
输入解释
The first line of the input contains an integer $T(1\leq T\leq 10000)$, denoting the number of test cases.

In each test case, there are two integers $n,m(1\leq n,m\leq 300000)$ in the first line, denoting the number of nodes and cameras.

In the second line, there are $n-1$ integers $f_2,f_3,...,f_n(1\leq f_i<i)$, denoting the father of each node.

In the third line, there are $n$ integers $a_1,a_2,...,a_n(1\leq a_i\leq 10^9)$, denoting the number of apples on each node.

For the next $m$ lines, each line contains three integers $x_i,k_i,c_i(1\leq x_i\leq n,0\leq k_i\leq n,1\leq c_i\leq 10^9)$, denoting each camera.

It is guaranteed that $\sum n\leq 10^6$ and $\sum m\leq 10^6$.
输出解释
For each test case, print a single line containing an integer, denoting the maximum amount of dollars Skywalkert can earn.
输入样例
1
6 3
1 1 2 2 3
2 5 4 3 3 2
2 1 3
3 1 7
1 2 4
输出样例
6
来自杭电HDUOJ的附加信息
Recommend liuyiding

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

源链接: HDU-6634

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

共提交 0

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