LearnPy Hub
← Arena
AdvancedRating 1700

Cheapest Flight With at Most k Stops

One-way flights have prices. Print the cheapest price from city s to city t using at most k stops in between (k + 1 flights), or -1.

Input

n, m, s, t and k; then m lines 'u v price'.

Output

One integer.

Sample 1

Input
4 5 1 4 1
1 2 100
2 3 100
2 4 600
3 4 200
1 3 100
Output
300

Sample 2

Input
3 3 1 3 0
1 2 100
2 3 100
1 3 500
Output
500
solution.py
Output appears here
Cheapest Flight With at Most k Stops · Python Arena problem · LearnPy Hub