JOI Park
InterviewTime limit1sMemory limit256 MB
Pick a distance X from square 1 to minimize C times X plus the total length of roads not fully inside the X radius.
- Level
Medium6 of 10
- Topics
- Shortest path, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
As part of the preparation for the olympics held in the IOI country in 20XX, JOI park is going to be renovated. JOI park has squares, numbered 1 to . The park also has roads that join the squares, numbered 1 to . Road () joins square and square in both directions, and its length is . From any square you can reach every other square by following roads.
The renovation plan goes as follows. A value for the subway construction is given. First, pick an integer that is at least 0 and join by subway every square whose distance from square 1 is at most , square 1 included. The distance between square and square is the smallest sum of road lengths over the routes from square to square . The subway construction costs in total.
Next, tear down every road that joins two squares linked by the subway. Tearing down a road is free.
Finally, repair every road left standing. Repairing a road of length costs .
JOI park has no subway before the renovation starts. Given the squares and roads of JOI park together with the value for the subway construction, write a program that computes the smallest cost of renovating JOI park.
Input
Standard input holds the following information.
- The first line holds the integers , , , separated by spaces. The park has squares and roads, and the value for the subway construction is .
- Each of the next lines holds the integers , , (), separated by spaces. Road joins square and square , and its length is .
Output
Print the smallest cost of renovating JOI park on one line.
Constraints
- ()
- ()
- ()
- and ()
- ()
- From any square you can reach every other square by following roads.