luogu#P7010. [CERC2013] Subway
[CERC2013] Subway
题目描述
Johny is going to visit his friend Michelle. His dad allowed him to go there on his own by subway. Johny loves traveling by subway and would gladly use this opportunity to spend half a day underground, but his dad obliged him to make as few line changes as possible. There are a lot of stations in the city, and several subway lines connecting them. All trains are perfectly synchronized the travel between two consecutive stations on every line takes exactly one minute, and changing lines at any station takes no time at all.
Given the subway map, help Johny to plan his trip so that he can travel for as long as possible, while still following his dad's order.
输入格式
First line of input contains the number of test cases . The descriptions of the test cases follow:
The description of each test case starts with an empty line. The next two lines begin with the strings Stops: and Lines:, and contain the names (separated by a comma and a space) of all subway stops and lines, respectively. A single line for each subway line follows (in no particular order), beginning with route: and listing the names of the stops along this particular line. The final two lines specify the names of the (different) stations nearby Johny's and Michelle's homes.
In each test case, there are at most stations and lines, whose total length does not exceed . The names of lines and stations are between and characters long and can contain letters, digits, hyphens apostrophes and and
signs (&). All lines are bidirectional (although changing the direction of travel counts as a line change) and there are no self-crossings.
输出格式
Print the answers to the test cases in the order in which they appear in the input. For each test case, print a single line summarizing the optimal route Johny can take (see example output for exact format). You may assume that such a route always exists.
题目大意
题目描述
准备去拜访他的朋友 。他的父亲允许他乘地铁独自去那里。 喜欢乘地铁旅行,并很愿意用这次机会在地铁里呆上半天,但是父亲要求他尽量减少换乘次数。这个城市有很多地铁车站,并有几条地铁线路连接它们。所有列车都完全同步——在每条线上的两个连续地铁站点之间地铁行驶的时间恰好需要 分钟,而在该城市的任何一个地铁站点上更改线路是不需要花费时间的。
现在 有了该城市的地铁线路图,请帮助 计划行程,以便他可以尽可能长时间的在地铁里呆着,同时还要尽量减少换乘次数。
输入格式
输入的第 行为测试数据 的数量。
每组测试数据均用空行分隔。接下来的两行以字符串以 和 开头,并分别包含所有地铁站和线路的名称(以逗号和空格分隔)。每条地铁线路中的其中一条线路(不分先后)从 开始,并一一列出了该条线路的站点名称。最后两行给定了 和 的家附近的车站的名称。
在每组测试数据中,最多有 个站点以及 条铁路线路,保证其总长度不超过 ;铁路线路和地铁站点的名称长度均在 至 个字符之间,其名称中可以含有字母、数字、连字符 -
、引号 '
和特殊符号 &
。所有的地铁线路都是双向的(改变行进方向即该条线路被改变),并保证没有自交叉。
输出格式
按照在输入中测试数据的顺序来输出每组测试数据的答案。对于每组测试用例,需输出一行来总结 Johny 可以采用的最佳路线(参见样例输出)。假设这样的线路始终存在。
输入输出样例
输入 #1
3
Stops: OxfordCircus, PiccadillyCircus, HydeParkCorner, King'sCross, GreenPark, Arsenal, Victoria, Highbury&Islington, LeicesterSquare
Lines: Blue, Cyan
Cyan route: Highbury&Islington, King'sCross, OxfordCircus, GreenPark, Victoria
Blue route: HydeParkCorner, GreenPark, PiccadillyCircus, LeicesterSquare, King'sCross, Arsenal
Johny lives at King'sCross
Michelle lives at GreenPark
Stops: OxfordCircus, PiccadillyCircus, HydeParkCorner, King'sCross, GreenPark, Arsenal, Victoria, Highbury&Islington, LeicesterSquare
Lines: Blue, Cyan
Cyan route: Highbury&Islington, King'sCross, OxfordCircus, GreenPark, Victoria
Blue route: HydeParkCorner, GreenPark, PiccadillyCircus, LeicesterSquare, King'sCross, Arsenal
Johny lives at PiccadillyCircus
Michelle lives at LeicesterSquare
Stops: OxfordCircus, PiccadillyCircus, HydeParkCorner, King'sCross, GreenPark, Arsenal, Victoria, Highbury&Islington, LeicesterSquare
Lines: Blue, Cyan
Cyan route: Highbury&Islington, King'sCross, OxfordCircus, GreenPark, Victoria
Blue route: HydeParkCorner, GreenPark, PiccadillyCircus, LeicesterSquare, King'sCross, Arsenal
Johny lives at Victoria
Michelle lives at HydeParkCorner
输出 #1
optimal travel from King'sCross to GreenPark: 1 line, 3 minutes
optimal travel from PiccadillyCircus to LeicesterSquare: 1 line, 1 minute
optimal travel from Victoria to HydeParkCorner: 2 lines, 7 minutes
说明 / 提示
时间限制:
内存限制:
3
Stops: OxfordCircus, PiccadillyCircus, HydeParkCorner, King'sCross, GreenPark, Arsenal, Victoria, Highbury&Islington, LeicesterSquare
Lines: Blue, Cyan
Cyan route: Highbury&Islington, King'sCross, OxfordCircus, GreenPark, Victoria
Blue route: HydeParkCorner, GreenPark, PiccadillyCircus, LeicesterSquare, King'sCross, Arsenal
Johny lives at King'sCross
Michelle lives at GreenPark
Stops: OxfordCircus, PiccadillyCircus, HydeParkCorner, King'sCross, GreenPark, Arsenal, Victoria, Highbury&Islington, LeicesterSquare
Lines: Blue, Cyan
Cyan route: Highbury&Islington, King'sCross, OxfordCircus, GreenPark, Victoria
Blue route: HydeParkCorner, GreenPark, PiccadillyCircus, LeicesterSquare, King'sCross, Arsenal
Johny lives at PiccadillyCircus
Michelle lives at LeicesterSquare
Stops: OxfordCircus, PiccadillyCircus, HydeParkCorner, King'sCross, GreenPark, Arsenal, Victoria, Highbury&Islington, LeicesterSquare
Lines: Blue, Cyan
Cyan route: Highbury&Islington, King'sCross, OxfordCircus, GreenPark, Victoria
Blue route: HydeParkCorner, GreenPark, PiccadillyCircus, LeicesterSquare, King'sCross, Arsenal
Johny lives at Victoria
Michelle lives at HydeParkCorner
optimal travel from King'sCross to GreenPark: 1 line, 3 minutes
optimal travel from PiccadillyCircus to LeicesterSquare: 1 line, 1 minute
optimal travel from Victoria to HydeParkCorner: 2 lines, 7 minutes
提示
Time limit: 8 s, Memory limit: 128 MB.