#P6096. [JSOI2015] 地铁线路
[JSOI2015] 地铁线路
Description
The subway in the JSOI Kingdom has become more expensive again. JYY, who is traveling in JSOI, is very unhappy. After this fare reform, passengers are not charged by travel distance, but by the number of transfers. JYY also needs to update his route search software accordingly. JYY thinks: if he pays the same fare, wouldn’t it be better for him if he can ride through more stations? So JYY wants to develop a route search program so that he can always “profit” the most.
The JSOI subway has lines and stations. Line contains stations. Each subway line is a straight line from its starting station to its terminal station (there are no weird circular lines like Beijing Subway Line 2 or Line 10). Also, each line runs in both directions. If different lines pass through the same station, passengers can transfer at that station. Under the latest JSOI subway fare rule, every time a passenger enters a running subway train, they must pay a fee of . Therefore, if a passenger transfers times in total, they need to pay fares. Since each line runs in both directions, at any station you may transfer to the opposite-direction train of the same line. Note that even transferring to the opposite direction of the same line still requires paying (because you always need to get off and then get on again).
Now JYY wants to take the subway from station to station . Assume that for any subway line, the travel time between two adjacent stations is minute, and stopping at stations and transferring both take no time. JYY wants to know:
- The minimum fare he needs to pay.
- Under the minimum fare, the maximum number of minutes he can spend riding the subway.
Input Format
The first line contains two positive integers and .
The second line contains space-separated strings, the names of the stations.
The next lines each describe one subway line. For line , the line first contains a positive integer , followed by strings, the station names on this line. A line is allowed to stop at the same station multiple times.
Line contains two different strings and , meaning JYY is currently at station and wants to go to station .
Output Format
The first line contains an integer , the minimum fare JYY needs to pay.
The second line contains an integer , the longest time he can ride the subway while spending .
If there is no route between the two stations, output -1 on the first line and 0 on the second line.
2 5
A B C D E
4 A B C D
3 C D E
A D
1
3
Hint
For of the testdata, , , .
It is guaranteed that the length of every input string does not exceed , and each string contains only letters, digits, and hyphen -.
Translated by ChatGPT 5
京公网安备 11011102002149号