{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eLittle 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.\u003cbr\u003e\u003cbr\u003eSkywalkert, 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.\u003cbr\u003e\u003cbr\u003eThe security system takes pictures of the nodes once per hour using $m$ cameras. Let\u0027s 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\u0027s 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.\u003cbr\u003e\u003cbr\u003eSkywalkert 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.\u003cbr\u003e\u003cbr\u003ePlease write a program to help Skywalkert make money optimally without being caught.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains an integer $T(1\\leq T\\leq 10000)$, denoting the number of test cases.\u003cbr\u003e\u003cbr\u003eIn 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.\u003cbr\u003e\u003cbr\u003eIn the second line, there are $n-1$ integers $f_2,f_3,...,f_n(1\\leq f_i\u0026lt;i)$, denoting the father of each node.\u003cbr\u003e\u003cbr\u003eIn 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.\u003cbr\u003e\u003cbr\u003eFor 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.\u003cbr\u003e\u003cbr\u003eIt is guaranteed that $\\sum n\\leq 10^6$ and $\\sum m\\leq 10^6$."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, print a single line containing an integer, denoting the maximum amount of dollars Skywalkert can earn."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n6 3\r\n1 1 2 2 3\r\n2 5 4 3 3 2\r\n2 1 3\r\n3 1 7\r\n1 2 4\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}