#P4103. [HEOI2014] 大工程
[HEOI2014] 大工程
Description
The country is undertaking a major project to build some new channels in a very large transportation network.
Our country has a very special layout. It can be regarded as a tree with unit edge weights, with cities at the vertices.
The cost of building a new channel between two cities is the length of the shortest path between on the tree.
There are many plans. In each plan, we select vertices, and then build new channels between every pair of them (exactly one between any two vertices).
For each plan, we want to know:
- The sum of the costs of these new channels.
- The minimum cost among these new channels.
- The maximum cost among these new channels.
Input Format
The first line contains , the number of vertices.
The next lines each contain two integers , indicating there is an edge between and . Vertices are numbered starting from .
The next line contains , the number of plans. For each plan, there are lines. The first line contains , the number of selected vertices in this plan.
The second line contains distinct integers separated by spaces, indicating which vertices are selected.
Output Format
Output lines. Each line contains three numbers: the sum of costs, the minimum cost, and the maximum cost.
10
2 1
3 2
4 1
5 2
6 4
7 5
8 6
9 7
10 9
5
2
5 4
2
10 4
2
5 2
2
6 1
2
6 1
3 3 3
6 6 6
1 1 1
2 2 2
2 2 2
Hint
For of the testdata, $1 \le n \le 10^6, 1 \le q \le 5 \times 10^4, \sum k \le 2 \times n$.
The specific limits for each test point are shown in the table below:
| Test point ID | Special property | |
|---|---|---|
| The tree is a chain | ||
Translated by ChatGPT 5
京公网安备 11011102002149号