{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eConsider a rooted tree consisting of $n$ vertices where the first vertex is the root.The $i$-th vertex is endowed with the value $v_i$.\u003c/p\u003e\n\u003cp\u003eNow you are given a positive integer $k$.An ordered pair of vertices $(x,y)$, indicating the $x$-th and the $y$-th vertices in the tree, is valid if it satisfies the following conditions:\u003c/p\u003e\n\u003cul\u003e\n \u003cli\u003e$x\\neq y$;\u003c/li\u003e\n \u003cli\u003eThe $x$-th vertex is not an ancestor of the $y$-th one;\u003c/li\u003e\n \u003cli\u003eThe $y$-th vertex is not an ancestor of the $x$-th one;\u003c/li\u003e\n \u003cli\u003eThe length of the shortest path connection these two vertices is up to $k$;\u003c/li\u003e\n \u003cli\u003eTake the value of the lowest common ancestor of these two vertices, denoted by $v_z$. Then $v_x+v_y\u003d2v_z$.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eCan you calculate the total number of valid pairs of vertices in this tree?\u003c/p\u003e\n\u003ch3\u003eInput\u003c/h3\u003e\n\u003cp\u003eThe first line contains two integers $n$ and $k~(1 \\le n, k \\le 10^5)$ which is described as above.\u003c/p\u003e\n\u003cp\u003eThe second line contains $n$ integers, the $i$-th of which is the value of the $i$-th vertex $v_i$ ($0 \\le v_i \\le n$).\u003c/p\u003e\n\u003cp\u003eThe third line contains $n-1$ integers, the $i$-th of which represents the index of the parent vertex of the $(i+1)$-th vertex.\u003c/p\u003e\n\u003cp\u003eWe guarantee that the given tree is indeed a tree.\u003c/p\u003e\n\u003ch3\u003eOutput\u003c/h3\u003e\n\u003cp\u003eOutput the number of valid pairs of vertices in a line.\u003c/p\u003e\n\u003cp\u003eTwo pairs $(x_1,y_1)$ and $(x_2,y_2)$ are regarded as the same if $x_1\u003dx_2$ and $y_1\u003dy_2$.\u003c/p\u003e"}},{"title":"Sample 1","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\u003e3 2\n1 2 3\n1 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003cbr /\u003e"}},{"title":"Sample 2","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\u003e3 1\n2 1 3\n1 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003cbr /\u003e"}},{"title":"Sample 3","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\u003e3 2\n2 1 3\n1 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003cbr /\u003e"}}]}