#P6589. 『JROI-1』 关系树
『JROI-1』 关系树
Description
A relationship tree is a tree consisting of vertices and undirected edges.
For a given graph , define the vertex-induced subgraph of on a vertex set as the graph consisting of the vertex set and all edges in the original graph whose both endpoints belong to .
A graph is defined to be clean if and only if for any two vertices in the graph, either and are not connected, or the distance is at most .
Xiao L wants to know, for a query pair (), how many pairs satisfy , such that the vertex-induced subgraph formed by all vertices with indices from to (including ) is clean. Moreover, he also wants you to output the sum of all interval lengths (i.e., ).
Since Xiao L likes asking questions, you need to answer a total of queries.
Input Format
The first line contains three integers , , , with the meanings as described above.
The next lines each contain two integers , , describing an edge.
The next lines each contain two integers , , representing a query.
Output Format
Output lines. Each line contains two integers: the number of valid pairs , and the sum of all interval lengths.
5 3 2
1 2
1 5
4 5
3 5
1 3
2 5
1 5
6 10
10 20
14 30
Hint
Sample 1 Explanation
The relationship tree formed is shown in the figure.

The valid are $(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(2,5),(3,3),(3,4),(3,5),(4,4),(4,5),(5,5)$.
The answers to the three queries are , , and , respectively.
Constraints
This problem uses bundled testdata.
- Subtask 1 ( ): .
- Subtask 2 ( ): , and the relationship tree is a chain.
- Subtask 3 ( ): .
- Subtask 4 ( Enhanced version testdata, time limit ): No special restrictions.
For all test cases (), it is guaranteed that , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号