#P15818. [JOI 2015 Final] JOI 公園
[JOI 2015 Final] JOI 公園
Problem Description
To prepare for the Olympics to be held in IOI Country in 20XX, it has been decided to renovate JOI Park in IOI Country. There are squares in JOI Park, numbered from to . There are roads connecting these squares, numbered from to . Road () bidirectionally connects square and square , and its length is . From any square, you can reach any other square by traveling along some roads.
The renovation plan is as follows: First, choose a non-negative integer . Then, between every pair of squares whose distance from square 1 is at most (including square 1 itself), connect them with an underground passage. Here, the distance between square and square is defined as the minimum possible sum of road lengths along a route from square to square . In the renovation plan, there is an integer related to the cost of building underground passages. The total cost to build these underground passages is .
Next, remove all roads between every pair of squares that are connected by underground passages. Removing roads costs nothing.
Finally, repair all roads that are not removed and remain. The cost to repair a road of length is .
Before the plan is carried out, there are no underground passages in JOI Park. Find the minimum total cost required to renovate JOI Park.
Task
Given the information about the squares and roads in JOI Park, and the integer related to the underground passage cost, write a program to compute the minimum total cost required to renovate JOI Park.
Input Format
Read the following data from standard input.
- The first line contains three integers separated by spaces. This means there are squares, roads, and the integer related to the underground passage renovation cost is .
- Each of the next lines, line (), contains three integers separated by spaces. This means road connects square and square , and its length is .
Output Format
Output one line to standard output containing one integer, which is the minimum total cost required to renovate JOI Park.
5 5 2
2 3 1
3 1 2
2 4 3
1 2 4
2 5 5
14
5 4 10
1 2 3
2 3 4
3 4 3
4 5 5
15
6 5 2
1 2 2
1 3 4
1 4 3
1 5 1
1 6 5
10
Hint
Sample Explanation 1
In this sample, choose , and connect every pair of squares whose distance from square 1 is at most (squares 1, 2, and 3) with underground passages. Then the total cost is . This is the minimum value.
Sample Explanation 2
In this sample, the total cost is minimized when .
Sample Explanation 3
In this sample, the total cost is minimized when choosing and connecting every pair of squares with underground passages.
Constraints
All input data satisfy the following conditions:
- .
- .
- .
- ().
- ().
- ().
- and (). (That is, there are no multiple edges, and the edges are undirected.)
- ().
- It is guaranteed that in the given input data, from any square you can reach any other square by traveling along some roads.
Subtasks
Subtask 1 [15 points]
Satisfies the following conditions:
- .
- .
- .
- ().
Subtask 2 [45 points]
Satisfies the following conditions:
- .
- .
Subtask 3 [40 points]
No additional constraints.
Translated by DeepSeek V3.2.
Translated by ChatGPT 5