(beginer) 最短路 UVA 11280 Flying to Fredericton
来源:互联网 发布:精华液推荐 知乎 编辑:程序博客网 时间:2024/06/09 15:06
Problem C
FLYING TO FREDERICTON
After being inspired by Salvador Dali's artwork, Brett decided he would like to travel to Fredericton, New Brunswick to visit the Beaverbrook Art Gallery.
Brett lives in Calgary, and would like to find the cheapest flight or flights that would take him to Fredericton. He knows that a direct flight from Calgary to Fredericton, if one exists, would be absurdly expensive, so he is willing to tolerate a certain number of stopovers. However, there are multiple airlines in Canada with so many different flights between different cities now, which makes it very difficult for Brett to find the least expensive way to Fredericton! Can you write a program to help Brett plan his route?
Map showing a sample of the flights that would take Brett to Fredericton.
You will be given a list of cities between and including Calgary and Fredericton. The cities will be given in order of "nearest" to "farthest". The first city will always be "Calgary" and the last "Fredericton".
You will also be given a list of flights between pairs of cities, and the associated cost for each flight, taxes included. There will never be a flight from a farther city to a nearer city - Brett has already discarded those flights, deeming them to be a waste of time and money. Bear in mind, however, that there may be more than one flight between any two cities, as Brett is considering flights from all airlines.
Finally, you are presented with a number of queries. Each query is a single integer indicating the maximum number of stopovers Brett will tolerate. For each query, your program must calculate the least total cost of flights that would take Brett from Calgary to Fredericton with no more than the requested number of stopovers.
Input
The first line of input contains a single number indicating the number of scenarios to process. A blank line precedes each scenario.
Each scenario begins with a number N (2 ≤ N ≤ 100), the number of cities, followed by N lines containing the names of the cities. A city name is a string of up to 20 uppercase and lowercase letters. Next is a number M (0 ≤ M ≤ 1000), the number of flights available, followed by M lines describing the flights. Each flight is described by its departure city, its destination city, and an integer representing its cost in dollars. The final line starts with Q (1 ≤ Q ≤ 10), the number of queries, followed by Q numbers indicating the maximum number of stopovers.
Output
For each scenario, your program should output the scenario number, followed by the least total cost of the flights for each query. Follow the format of the sample output. If no flights can satisfy a query, write "No satisfactory flights". Output a blank line between scenarios.
Sample Input
24CalgaryWinnipegOttawaFredericton6Calgary Winnipeg 125Calgary Ottawa 300Winnipeg Fredericton 325Winnipeg Ottawa 100Calgary Fredericton 875Ottawa Fredericton 1753 2 1 03CalgaryMontrealFredericton2Calgary Montreal 300Montreal Fredericton 3251 0
Output for the Sample Input
Scenario #1Total cost of flight(s) is $400Total cost of flight(s) is $450Total cost of flight(s) is $875Scenario #2No satisfactory flights
- (beginer) 最短路 UVA 11280 Flying to Fredericton
- UVA 11280 Flying to Fredericton 最短路DP
- UVA 11280 - Flying to Fredericton(最短路)
- uva 11280 - Flying to Fredericton(最短路)
- UVA 11280 - Flying to Fredericton
- UVA 11280 Flying to Fredericton
- Flying to Fredericton UVA
- Bellman_Ford uva 11280 - Flying to Fredericton
- UVA 11280 - Flying to Fredericton SPFA变形
- UVA - 11280 Flying to Fredericton(SPFA)
- UVA - 11280 Flying to Fredericton(二维SPFA)
- (beginer)最短路 UVA 10603 Fill
- (beginer) 最短路 UVA 558 Wormholes
- (beginer) 最短路 UVA 10269 Adventure of Super Mario
- (beginer)最短路 UVA 11367 Full Tank?
- (beginer) 最短路 UVA 10246 Asterix and Obelix
- (beginer) 最短路 UVA 658 It\'s not a Bug, it\'s a Feature!
- uva 11280 状态压缩+最短路
- (intermediate)DFS (强连通+缩点+拓扑排序) UVA 11098 - Battle II
- (beginer)最短路 UVA 10603 Fill
- (beginer) 最短路 UVA 10269 Adventure of Super Mario
- select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET
- (beginer)最短路 UVA 11367 Full Tank?
- (beginer) 最短路 UVA 11280 Flying to Fredericton
- stdClass详解
- jps 进程状态工具
- (beginer) 最短路 UVA 10246 Asterix and Obelix
- (beginer) 最短路 UVA 558 Wormholes
- REDHAT(LINUX) 扩 /HOME 所在LV
- (beginer) 最短路 UVA 658 It\'s not a Bug, it\'s a Feature!
- (intermediate)最短路(最长路) UVA 1348 - Tomato Automata
- (intermediate) 最短路(差分约束+拓扑排序) UVA 1516 - Smoking gun