#P10302. [THUWC 2020] 某科学的动态仙人掌
[THUWC 2020] 某科学的动态仙人掌
Problem Description
The title is just to attract you to click in.
You are given a tree whose edge weights are , and a constant . The nodes are labeled with 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 , where can be any positive integer, such that:
- ;
- ;
- For any , ;
- For any , .
Define an "-block" as a set of nodes satisfying:
- For any and any in the complement of with , and are not -connected;
- For any , and are -connected;
- For any , .
Input Format
The first line contains three integers , , , denoting the number of nodes in the tree, the number of queries, and the constant , respectively.
The second line contains integers , 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 integers , meaning the interval of this query is . It is guaranteed that .
Constraints: , .
Output Format
Output lines, answering the queries in order. For each query, output one integer per line, which is the answer to this 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
This problem has multiple subtasks. Each subtask may contain multiple test points, and 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 constraints, as shown in the table below:
| Subtask | Score | Property 1 | Property 2 | |||
|---|---|---|---|---|---|---|
| No | No | |||||
| Yes | ||||||
| No | Yes | |||||
| Yes | ||||||
| No | ||||||
Here, the meanings of Property 1 and Property 2 are as follows.
Property 1: There exists a node such that .
Property 2: , and for the -th query, .
Translated by ChatGPT 5