Problem J
Shopping Malls
We want to create a smartphone application to help visitors of a shopping mall and you have to calculate the shortest path between pairs of locations in the mall. Given the current location of the visitor and his destination, the application will show the shortest walking path (in meters) to arrive to the destination.
The mall has
-
If walking or taking the stairs the distance is the euclidean distance between the points.
-
Using the lift has a cost of 1 meter because once we enter the lift we do not walk at all. One lift can only connect 2 points. An actual lift connects the same point of different floors, in the map all the points connected by a lift have the corresponding edge. So you do not need to worry about that. For instance, if there are three floors and one lift at position
of each floor, the input contains the edges , , and . In some maps it can be possible that a lift does not connect all the floors, then some of the edges will not be in the input. -
The escalator has two uses:
-
Moving from A to B (proper direction) the cost is 1 meter because we only walk a few steps and then the escalator moves us.
-
Moving from B to A (opposite direction) has a cost of the euclidean distance between B and A multiplied by a factor of 3.
-
The shortest walking path must use only these connections. All the places are connected to each other by at least one path.
Input
Each input file contains the map of a unique shopping mall and a list of queries.
The first line contains two integers
The next
The next line contains an integer
Output
For each query write a line with the shortest path in walked meters from the origin to the destination, with each place separated by a space.
Sample Input 1 | Sample Output 1 |
---|---|
6 7 3 2 3 3 5 3 2 2 3 2 6 4 1 1 3 1 4 2 0 1 walking 0 2 lift 1 2 stairs 2 3 walking 3 4 escalator 5 3 escalator 4 5 walking 5 0 1 1 2 3 5 5 3 5 1 |
0 1 1 0 2 3 4 5 5 3 5 3 2 0 1 |