#BF0000006. Bay đến Fredericton (Flying to Fredericton)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bay đến Fredericton (Flying to Fredericton)
Flying to Fredericton
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Find cheapest Calgary to Fredericton fares with no more than the queried number of stopovers.
A traveler wants to fly from Calgary to Fredericton. The cities are listed from nearest to farthest: Calgary first and Fredericton last. Every flight goes from an earlier city in this list to a later city, and multiple airlines may offer different fares between the same city pair.
There are queries. Each query specifies the maximum number of intermediate stopovers the traveler accepts. Find the minimum Calgary-to-Fredericton airfare using no more than flights, or print the prescribed message if no suitable journey exists. All queries share the same flight network.
Input
Read , then city names (Calgary first, Fredericton last), flight records (from, to, fare), and followed by allowed stop counts.
Output
Print Scenario #1, then Total cost of flight(s) is $X or No satisfactory flights for each query.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; city names distinct, at most 20 letters.
- Subtask 2 (30 points): ; ; ; ; ; city names distinct, at most 20 letters.
- Subtask 3 (50 points): ; ; ; ; ; city names distinct, at most 20 letters.
Examples
Input
4
Calgary
Winnipeg
Ottawa
Fredericton
6
Calgary Winnipeg 125
Calgary Ottawa 300
Winnipeg Fredericton 325
Winnipeg Ottawa 100
Calgary Fredericton 875
Ottawa Fredericton 175
3 2 1 0
Output
Scenario #1
Total cost of flight(s) is $400
Total cost of flight(s) is $450
Total cost of flight(s) is $875
Explanation
The three stop limits 2, 1, 0 yield minimum fares of , , respectively.