Journey from Petersburg to Moscow
Time limit3sMemory limit512 MB
Find the minimum cost path from city 1 to city n where only the k most expensive edges of the path are paid for, or all edges if the path has k or fewer.
- Level
Hard9 of 10
- Topics
- Graph, Shortest path, Sorting, Greedy
- Solved
- No attempts yet
Problem
A network of toll roads was built in the European part of Russia for the World Programming Cup 2112. The network consists of bidirectional roads that connect cities. Each road connects two distinct cities, no two roads connect the same pair of cities, and you can travel from any city to any other city using only this network. To keep charging simple, no two roads cross outside of the cities.
Every road has its own positive cost. Normally a driver who uses these toll roads pays the sum of the costs of all roads on the trip. To attract more car travel between the two capitals, the operator Radishchev Inc introduced a special offer: on a journey from Saint Petersburg to Moscow you pay only for the most expensive roads of your path.
More precisely, suppose a path consists of roads. Let be the cost of the most expensive road on the path, the cost of the second most expensive one, and so on, so that . If , the path is too short for the offer and the driver pays the sum of all costs as usual, that is . If , the driver pays only for the most expensive roads, that is .
As the chief analyst of Radishchev Inc, compute the cheapest possible journey from Saint Petersburg to Moscow.
Input
The first line contains three integers , and (, , ): the number of cities, the number of roads, and the largest number of roads one pays for on a single journey.
Each of the next lines describes one road with three integers , and (, , ): a bidirectional road between cities and that costs in either direction. At most one road connects each pair of cities, and the given roads let you reach every city from every other city.
Output
Print one integer, the minimum possible cost of a journey from city (Saint Petersburg) to city (Moscow).