|
||||||||||
Salty FishTime Limit: 4000/4000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 214 Accepted Submission(s): 84 Problem Description 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. Input 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$. Output For each test case, print a single line containing an integer, denoting the maximum amount of dollars Skywalkert can earn. Sample Input
Sample Output
Source | ||||||||||
|