cities cities numbered 0 to cities - 1 and a list of direct flights flights: flight [a, b, price] goes from city a to city b and costs price.
You need to get from city origin to city destination with at most max_stops layovers (intermediate cities). Return the lowest total cost of such a trip, or -1 if it is impossible.cities=4, flights=[[0, 1, 50], [1, 3, 50], [0, 2, 20], [2, 1, 10], [0, 3, 300]], origin=0, destination=3, max_stops=1 → 100
The route 0 → 2 → 1 → 3 costs 80 but has two layovers. With at most one, the best is 0 → 1 → 3 for 100.
cities=4, flights=[[0, 1, 50], [1, 3, 50], [0, 2, 20], [2, 1, 10], [0, 3, 300]], origin=0, destination=3, max_stops=2 → 80
Two layovers are now allowed, so 0 → 2 → 1 → 3 for 80 works.
cities=3, flights=[[1, 0, 40]], origin=0, destination=2, max_stops=2 → -1
There are no flights out of city 0 at all.
cities=4, flights=[[0, 1, 50], [1, 3, 50], [0, 2, 20], [2, 1, 10], [0, 3, 300]], origin=0, destination=3, max_stops=1
100
Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.