F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Salty Fish

Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 213    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
1 6 3 1 1 2 2 3 2 5 4 3 3 2 2 1 3 3 1 7 1 2 4
 

Sample Output
6
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-20 11:25:47, Gzip enabled