#P8626. [蓝桥杯 2015 省 A] 灾后重建
[蓝桥杯 2015 省 A] 灾后重建
Description
Pear City has a total of () settlements, and there are () undirected roads connecting these settlements. Any two settlements can reach each other through these undirected roads. This situation lasted until recently, when a severe earthquake destroyed all roads.
After the earthquake, Pear plans to repair some of the roads. Repairing the -th road takes time. However, Pear does not plan to make all nodes connected; instead, he chooses some specially indexed nodes and makes them connected.
Pear has () queries. In each query, he selects all nodes whose indices are in and whose index satisfies , and repairs some roads to make these nodes connected. Since all road repairs can start at the same time, the completion time depends on the road that takes the longest time, that is, the maximum among the roads involved.
Can you help Pear compute the minimum time needed for each query? The queries are independent, meaning the repair plan in one query is not actually carried out.
Input Format
The first line contains three positive integers , , and , as described above.
The next lines each contain three positive integers , , and , representing an undirected road between and that takes time to repair. Self-loops and multiple edges may exist. .
The next lines each contain four positive integers , , , and , indicating that the nodes in this query are all nodes in the interval whose indices satisfy . It is guaranteed that at least two nodes participate in each query.
Output Format
Output lines. Each line contains one positive integer, the answer to the corresponding query.
7 10 4
1 3 10
2 6 9
4 1 5
3 7 4
3 6 9
1 5 8
2 7 4
3 2 10
1 7 6
7 6 9
1 7 1 0
1 7 3 1
2 5 1 0
3 7 2 1
9
6
8
8
Hint
For of the testdata, .
For of the testdata, .
For of the testdata, , , , . , , and are all in the range , and is in the range .
Time limit: 5 seconds, 256 MB.
Lanqiao Cup 2015 Provincial Contest A Division, Problem J.
Translated by ChatGPT 5
京公网安备 11011102002149号