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.
Hard9GraphShortest pathSortingGreedyNo attempts yetTime limit3sMemory limit512 MBA network of toll roads was built in the European part of Russia for the World Programming Cup 2112. The network consists of m bidirectional roads that connect n 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 k most expensive roads of your path.
More precisely, suppose a path consists of l roads. Let c1 be the cost of the most expensive road on the path, c2 the cost of the second most expensive one, and so on, so that c1≥c2≥c3≥⋯≥cl. If l≤k, the path is too short for the offer and the driver pays the sum of all costs as usual, that is ∑i=1lci. If l>k, the driver pays only for the k most expensive roads, that is ∑i=1kci.
As the chief analyst of Radishchev Inc, compute the cheapest possible journey from Saint Petersburg to Moscow.
The first line contains three integers n, m and k (2≤n≤3000, 1≤m≤3000, 1≤k<n): 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 m lines describes one road with three integers ui, vi and wi (1≤ui,vi≤n, ui=vi, 1≤wi≤109): a bidirectional road between cities ui and vi that costs wi 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.
Print one integer, the minimum possible cost of a journey from city 1 (Saint Petersburg) to city n (Moscow).