Given a tree with N nodes, and two integers A and B.
Every node has a magic value \(M_{i}\) (1<=i<=N) associated with it.
Consider Node 1 as root of the tree.
There are Q queries of type -
- X U V , where you have to find the number of nodes Y in the subtree of node X such that -
- A <= Distance ( X, Y ) <= B
- U <= Magic value of Y <= V
Note : Distance ( X, Y ) - Number of edges in path from X to Y.
Input Format
First line contain three integers N,A,B, number of nodes and A,B .
Next line contains N integers, \(M_{i}\) magic value of each Node from 1 to N.
Next line contains N-1 space separated integers, \(P_{i}\) parent of each Node from 2 to N .
Next line contain Q, number of queries.
Next Q lines contains queries of type as mentioned above.
Output Format
Answer corresponding to each query in a single line .
Constraints
1<= N, Mi, Q, A, B, U, V <= 10^5,
1<= Pi < i
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
No editorial available for this problem.