As the newly elected mayor of Kitchener, Alanna's first job is to improve the city's road plan.
Kitchener's current road plan can be represented as a collection of intersections with roads, where the road has length meters, costs dollars per year to maintain, and connects intersections and . To create a plan, Alanna must select some subset of the roads to keep and maintain, and that plan's cost is the sum of maintenance costs of all roads in that subset.
To lower the city's annual spending, Alanna would like to minimize the plan's cost. However, the city also requires that she minimizes travel distances between intersections and will reject any plan that does not conform to those rules. Formally, for any pair of intersections , if there exists a path from to taking meters on the existing road plan, Alanna's plan must also include a path between those intersections that is at most meters.
输入格式
The first line contains the integers and .
Each of the next lines contains the integers and , meaning that there currently exists a road from intersection to intersection with length and cost .
The following table shows how the available 15 marks are distributed.
Marks
Bounds on and
Bounds on
Bounds on
Additional Constraints
marks
,
None.
marks
There is at most one road between any unordered pair of intersections.
None.
输出格式
Output one integer, the minimum possible cost of a road plan that meets the requirements.