Shortest Path with Exactly K Edges

MEDIUM-HARD · C · 3000ms

For the closing ceremony's trivia round, Wasif needs the shortest-cost route between two nodes using EXACTLY K hops on the university network graph — no more, no fewer. Given a weighted directed graph with N nodes and M edges, and a source S, target T, and integer K, print the minimum total weight of a path from S to T that uses EXACTLY K edges (edges/nodes may repeat), or -1 if impossible.

Input

Line1: N M K S T. Next M lines: u v w (directed edge u→v, weight w).

Output

Minimum weight path using exactly K edges, or -1.

Constraints

1 ≤ N ≤ 100, K ≤ 1000

Sample Input

4 4 2 1 4
1 2 1
2 3 1
3 4 1
1 4 100

Sample Output

2
main.c
Loading editor…

Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.

Shortest Path with Exactly K Edges · DIU ContestHub