Shortest Path Revisited
Practice
3.8 (52 votes)
Algorithms
C++
Graphs
Shortest path algorithm
Problem
86% Success 8141 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

In the country of HackerEarth, there are N cities and M bi - directional roads. We need to transport essential items from City  to all other cities. (There exists a path always)

But every road has some positive amount of Toll Charge associated with it say C (it is not same for all roads). We need to find the minimum amount of charge that it required to deliver essential items for each city.

Fortunately, to our rescue we have special offers, which means while travelling from City 1 to any other city we can select at-most K roads and we will not be charged for using those roads. 

Can you now find the minimum charge that we have to pay to deliver essential items for each city.

(Remember we require to provide answers for each destination city separately i.e. we have K offers for every city and not as a whole)

Input :
1. First line contain three integers N M K.
2. Next M lines contain three integers U V W, denoting a road between city U and city v with Toll Charge W.

Constraints :
\(1 <= N <= 10^5, 1 <= M <= 5*10^5\)
\(1 <= U, V <= N \)
\(1 <= W <= 10^6\)
\(1 <= K <= 18\)

Output :
Print N space separated integers , denoting the minimum charge we require to pay for each city , where first integer represent cost for City 1, second for City 2 and so on.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
17 votes
Tags:
AlgorithmsApprovedDijkstra's algorithmGraphsMediumShortest Path Algorithm
Points:30
20 votes
Tags:
AlgorithmsDijkstra's algorithmGraphsMediumShortest Path Algorithm
Points:30
2 votes
Tags:
GraphsAlgorithmsShortest Path Algorithms