#BF0000005. Vé máy bay rẻ nhất với K điểm dừng (Cheapest Flights Within K Stops)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Vé máy bay rẻ nhất với K điểm dừng (Cheapest Flights Within K Stops)
Cheapest Flights Within K Stops
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Find the cheapest directed flight route from src to dst allowing at most k intermediate stops.
There are cities numbered through and directed flights. Each flight costs a positive integer . Find a cheapest itinerary from city src to city dst.
The itinerary is allowed to have at most intermediate stops. A direct flight has zero stops, while a two-flight journey through a transfer city has one stop. Therefore, at most flights can be taken. Print the cheapest eligible total fare, or -1 if no eligible itinerary exists.
Input
First line: (PHOJ input adaptation). Next lines .
Output
Print the minimum fare or -1 if none exists.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Examples
Input
4 5 0 3 1
0 1 100
1 2 100
2 0 100
1 3 600
2 3 200
Output
700
Explanation
With , route costs ; the cheaper three-edge route has too many stops.