#P9992. [Ynoi Easy Round 2024] TEST_130
[Ynoi Easy Round 2024] TEST_130
Problem Description
Given a rooted tree with nodes, define (where is a vertex of the tree and is a non-negative integer) as the set of nodes in the subtree rooted at whose distance to is at most .
There are queries. Each query gives and asks for the size of .
Input Format
The first line contains two integers .
The second line contains integers , where denotes the parent of node .
The next lines each contain two integers , representing one query.
Output Format
Output lines. Each line is the answer to the corresponding query in order.
5 4
1 2 2 3
3 1
3 0
5 0
1 2
3
1
1
7
Hint
Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: ccz181078.
Constraints: For of the data, , , , .
For of the data, .
For another of the data, .
For another of the data, .
For the remaining of the data, there are no special restrictions.
Translated by ChatGPT 5