当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2360:Trains

题目描述
Trains are cool. You can get pretty much anywhere in Europe on a train, including little towns. In Canada, train service is not quite as good. Sometimes you have to change trains many times, and it's often hard to know the quickest route and where to switch. Depending on the time of day, the route may even pass through completely different cities. Fortunately, you can write a program to help you. Given the schedules of trains running between different places, your task is to find all the shortest connections between two places. A shortest connection is one for which there is no other connection that would allow you to leave later and arrive at the same time or earlier, or leave at the same time and arrive earlier. Time to change trains need not be considered, as it is already built into the schedule.
输入解释
The first line of input contains a positive integer N, the number of test cases. The first line of each test case contains T <= 20, the number of train routes. Each train route is described by one or more lines containing:
  • S <= 20 The number of stations on the route including origin and terminus.
  • hh:mm The starting time of the route (in 24-hour clock notation; that is, in the range 00:00 to 23:59). You may assume that a train leaves the origin every day at this time. A station name is a string of no more than 40 alphabetic characters.
  • A list of the names of the S stations, separated by the travel time between adjacent stations. Travel time is given in hours and minutes.

Finally, each test case gives the name of an origin and destination for which a schedule is to be generated. You may assume there is at least one route from the specified origin to the specified destination.
输出解释
The output consists of a list of shortest connection departure and travel times from the origin to the destination, ordered by departure time. Each combination of departure and travel time should be listed only once, even if there are multiple routings yielding the same connection times. The departure time should be given as hh:mm (that is, exactly 2 digits each). Travel time on the other hand should be given as h:mm, hh:mm, hhh:mm, etc., as appropriate to avoid unnecessary leading 0's. Leave an empty line between the output for successive test cases.
For example, the first route in the sample input begins in Windsor at 08:00 a.m., arrives in London at 09:55, in Kitchener at 11:30, Guelph at 12:25, Toronto at 13:30 and Montreal at 18:20. To get from Waterloo to Toronto we can leave at 07:00 and travel direct for a total time of 1:45. Or we can leave at 08:00 and travel to Kitchener, then to Guelph and Toronto, arriving at 13:30 for a travel time of 5:30. Or we can depart Waterloo at 09:00 for Hamilton, Niagara, and Toronto, arriving at 14:00. Finally, we can depart Waterloo at 23:00 and arrive in Toronto at 07:05 the next morning, for a travel time of 8:05.
输入样例
1
7
6 08:00 Windsor 1:55 London 1:35 Kitchener 0:55 Guelph 1:05 Toronto 4:50 Montreal
2 08:00 Waterloo 0:45 Kitchener
3 09:00 Waterloo 1:45 Hamilton 1:05 Niagara
2 12:00 Niagara 2:00 Toronto
2 07:00 Waterloo 1:45 Toronto
2 23:00 Waterloo 0:55 Guelph
2 06:00 Guelph 1:05 Toronto
Waterloo Toronto
输出样例
07:00 1:45
08:00 5:30
09:00 5:00
23:00 8:05

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2360

最后修改于 2020-10-29T06:30:32+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1500 65536