AlgoUniversity
  • Go Back
Discussion
Minimum Cost Path :

Author

Rishabh Verma

Difficulty Level : Hard

Submissions : 2310

Asked In : deshaw

Marks :50

: 21 | : 0

Given a weighted directed graph with n nodes and m edges, find the minimum cost of a path from node 0 to node n-1 that contains at most k edges. if no such path exist print -1.

cost of a particular path between two nodes is defined as the maximum weight of any edge that exists in the path.

Input

First line contains three integers n, m and k (number of nodes , number of edges, maximum number of edges allowed in path).

In next m lines each line represents an edge as u, v and w ( an edge between u and v with w weight).

Output

print a single digit answer denoting the minimum cost of path with at most k edges.

Examples

Input
4 5 2
0 1 5
1 3 6
0 2 6
2 3 5
2 2 5
Output
6
Input
5 5 2
0 1 5
1 2 6
2 4 6
0 3 5
3 4 5
Output
5

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.