Limits 2s, 512 MB

You are given a tree of nn vertices. Each vertex contains an integer. Vertex 1 is the root of the tree, each of the n1n-1 remaining vertices has a parent in the tree. A vertex is connected with its parent by an edge. The parent of vertex i is vertex pip_i. The parent index is always less than the index of the vertex (i.e., pi<ip_i < i).

We say that vertex uu is in the sub-tree of vertex vv, if we can get from uu to vv, moving from the vertex to the parent. In particular, vertex vv is in its sub-tree.

You will be given mm queries, the ii-th of which consists of two numbers: vv and xx. You need to find out how many of vertices of sub-tree vv consists value greater than or equal to xx, that means auxa_u ≥ x, where vertex uu is in the sub-tree of vertex vv.

Input

The first line contains two integers nn and mm (1n,m5×1051 ≤ n, m ≤ 5 × 10^5), the number of nodes in the tree and queries, respectively.

The following line contains n1n-1 integers p2p_2, p3p_3, ..., pnp_n (1pi<i1 ≤ p_i < i), the parents of vertices from the second to the nn-th.

The next line contains n integers, the ii-th of these integers aia_i (1ai1091 ≤ a_i ≤ 10^9) is written on vertex ii.

The next mm lines describe the queries, the ii-th line contains two numbers vv (1vn1 ≤ v ≤ n) and xx (1x1091 ≤ x ≤ 10^9), the vertex and the depth that appear in the ii-th query.

Output

For each query, print the number of vertices of sub-tree vv consists value greater than or equal to xx.

Sample

InputOutput
3 2
1 2
5 6 7
1 3
1 6
3
2

Submit

Login to submit.

Statistics

92% Solution Ratio
fsshakkhorEarliest, Apr '19
mahabub.tweetFastest, 0.0s
mdshadeshLightest, 81 kB
SoudipShortest, 723B
Toph uses cookies. By continuing you agree to our Cookie Policy.