#P7126. [Ynoi2008] rdCcot
[Ynoi2008] rdCcot
Problem Description
Given a tree whose edge weights are all and a constant . The nodes are labeled by integers from to .
Define as the distance between nodes and on the tree, i.e., the sum of edge weights on the simple path from to . In particular, .
In each query, an interval is given. You need to ask how many -blocks there are, defined as follows:
For any two nodes , define that and are -connected if and only if there exists a node sequence of length such that:
- .
- .
- For any , .
- For any , .
Define a "-block" as a set of nodes such that:
- For any and any in the complement of , and are not -connected.
- For any , and are -connected.
- For any , .
Input Format
The first line contains three numbers , , , representing the number of nodes in the tree, the number of queries, and the constant , respectively.
The second line contains numbers , meaning that for each integer with , there is an undirected edge between and .
It is guaranteed that the input forms a tree.
Then follow lines, each containing two numbers , indicating that the interval of this query is , and it is guaranteed that .
Constraints: , .
Output Format
Output lines, answering the queries in order. Each line contains one integer, representing the answer to that query.
10 9 2
1 1 1 2 3 4 1 1 1
1 3
2 4
3 5
4 6
5 7
6 8
7 9
8 10
5 5
1
1
2
3
3
3
2
1
1
Hint
Idea: nzhtl1477, Solution: ccz181078, Code: nzhtl1477&ccz181078, Data: ccz181078.
This problem has multiple subtasks. Each subtask may contain multiple test points. You can get the score of a subtask only if you pass all test points in that subtask.
The test points of each subtask satisfy some special restrictions, as shown in the table below:

The meanings of Property 1 and Property 2 are as follows:
Property 1: There exists a node such that .
Property 2: , and in the -th query, .
Translated by ChatGPT 5