Finding the shortest route between cities.
The input consists of the following sections:
-
Map: The first line contains the dimensions of the map: width
wand heighth. The nexthlines (each containingwcharacters) describe the map. Each character represents:.: Empty field#: Road*: City- Letter or number: Part of the city name
-
Flight Connections: The next line contains a single integer
k- the number of flight connections. The followingklines describe the connections in the formatsource destination time, wheresourceis the name of the starting city,destinationis the name of the destination city, andtimeis the flight time in minutes. -
Queries: The next line contains a single integer
q- the number of queries. Each query appears on a separate line and has the formatsource destination type. Thetypeindicates the query type:- If
typeis zero, the query is only for the time. - If
typeis one, the route should also be provided.
- If
For each query, the output should be as follows:
- If the query type is zero, output one line with the number representing the shortest travel time between the cities.
- If the query type is one, output one line with the number representing the shortest travel time between the cities, followed by the intermediate cities (excluding the starting and ending cities) in the order they were visited, separated by spaces.
20 20
.........GDANSK.....
........*...........
........#...........
........#...........
*##################.
#SZCZECIN.........#.
#.................#.
##................#.
.############*#####.
.#...WARSZAWA.......
.#..................
.#############......
.#...........#......
.#..WROCLAW.##......
.#..*.......*.......
.####.......#KIELCE.
......*##.#########.
.OPOLE..#.*.......#.
........#.KRAKOW..#.
........###########.
0
3
KIELCE KRAKOW 0
KRAKOW GDANSK 0
KRAKOW GDANSK 1
5
40
40 KIELCE SZCZECIN
1549
2258
931
784
1610
935
Time: <0.25s
