A frustrating part of arranging your own air travel trip is selecting from among many possible flights that sequence of flights which will take you from your origin to your destination in the least possible time or for the least possible cost. It should be clear to any frequent air passenger that in order to reach one city from another, the cost of the shorter flight may be more than the cost of longer flights. In other words, it may pay you well to cool your heels in an airport waiting for a connecting flight rather than take a more direct flight or one in which the connecting time is shorter. For example, consider the following flight schedule. CenterCity CenterCity Homeville Homeville Greenville Greenville 5:2OA 6:55A 12.50 5:45A 9:l5A 35.00 7:45A 9:35A 20.00 In order to travel from CenterCity to Homeville, you have two choices. You can travel from CenterCity to Homeville, then from Homeville to Greenville, or you can travel directly from CenterCity to Greenville. The first route costs $32.50 and has travel time 4:15; the direct route costs $35.00 and has travel time 3:30. If minimizing cost is your objective, then you would choose the first route. If you want to minimize time, you would select the second route. You are to write a program to optimize route selection given the criteria of least cost or least time. Your program will read a list of flights and several trip requests and will select from the list of flights the best sequence to satisfy each trip request. For each request, if more than one route should satisfy the request, then your program should select the route that also satisfies the other objective. For example, if cost is to be minimized and if two routes both yield the minimum cost, then select the route which yields the shortest travel time. There is only one valid solution for each input in the data set. Input The input data will consist of various test cases. Each case begins with line ‘TRAVEL XXX’, where XXX is ID number of the travel. ID number is a positive integer with leading zeroes. There will be less than 100 tests. Each test is broken into two segments, the first describing the list of flights and the last containing the trip requests. The end of each part of the test is indicated by the line consisting of the single character ‘#’. The flight segment of the test describes individual flights, one per line. Each line contains the origin city (begins from column 1), the destination city (begins from column 18), the departure time (begins from column 34), the arrival time (begins from column 42), and the cost (columns 52 through 62). City names are left-justified in their respective fields, and may only contain upper and lower case characters. City names like ‘CITY’ and ‘cItY’ are same and lengths of city names will be less than 17 symbols. Times are in the form ‘HH:MMX’, where HH is the hour (a leading zero may be replaced by a blank), MM is the minutes (exactly two digits will appear), and X is ‘A’ (for AM), ‘P’ (for PM). The cost of the ticket is in dollars and cents, and includes a decimal point and two fractional digits. No tickets are free or cost more than $999.99. Departure times are always prior to arrival times. All individual flights represented by a line in the schedule take less than 24 hours. There will be at most 50 flights and at most 20 cities on the schedule. There will be no unnecessary blanks and spaces in the first part of a test. The trip request segment of the file immediately follows the list of flights. Each request appears on a line by itself, and specifies the origin city, the destination city, and whether to optimize cost or travel
2/3 time. If it is desired to optimize travel time, the word ‘TIME’ is displayed. If cost is to be optimized, then the word ‘COST’ is displayed. There may be leading and trailing blanks in any line in the trip requests. The end-of-file indicates the end of the input file. Output For the first line of each test display ‘Requests and optimal routes for travel Y ’ without quotes where Y is an ID number of the test shown in the input and must be without leading zeroes. You can find all cases of the output format in the sample output and your output must be identical. All optimum routes will require less than 10 days and less than $1,000.00. Place one blank line between the outputs for successive trips and two blank lines between successive tests. Sample Input TRAVEL 001 CenterCity CenterCity Homeville ArcherCity
CenterCity ArcherCity
TRAVEL 992 GreenVille GreenMile AA ZZZ ZZZZ ZZZZZ
Centercity Homeville 5:20A 6:55A $12.50 Homeville Greenville 7:45A 9:35A $20.00 ----------------------- 4:15 $32.50 Optimize: Cost
1 day 4:35 $632.50
2 days 23:57 $1.50