Navigation
Time Limit: 1 Second Memory Limit: 32768 KB
There is a computer game which had been quite popular in China about 7 years ago named "Uncharted Waters II". This game has several versions on different platforms and the plot of this game is mainly about a young captain's voyage in the 16th century. There is a useful command in gameplay - devolve. With this command, you can only specify a port and your assistant will automatically guide you there via the shortest path.
(Screenshots for Uncharted Waters on SNES/SFC with emulator ZSNES)
As the topology is quite complicated, finding the shortest path between every two points seemed to be an impossible task at that time with only 486 computers. Actually, the game adopted a special method to get an approximation: There're some pre-set paths between the ports, and whenever you used the devolve command, your assistant first leads your ship to one of the shortest paths as quick as possible and then get to the target port along some preset paths.
One day, your assistant has retired and now you have to write a program to help yourself. Let's first suppose that the surface of the Earth is a plane(It was believed so at that time, wasn't it?), thus all ports can be represented by two coordinates x and y. All the pre-set paths are straight lines connecting two ports.
Now, given the coordinates of all ports and the ports that each pre-set path
connects, you are to calculate the shortest paths between given pairs of initial
position and a target port. Your result should satisfy:
1. It is (one of) the path(s) that reaches the pre-set paths as early as possible.
2. Under condition 1, it's (one of) the path(s) that reaches the target port
as early as possible.
Input
The input contains several test cases. The first line of each case has 3 integers,
N (1 <= N <= 50), M and L. N is the number of ports, M is the number of
preset paths, L is the number of pairs of initial position and target port.
The following N lines each contains a name consists of no more than 15 letters
followed by two real numbers representing the coordinates of that port.
The next M lines each contain the names of the 2 ports that path connects.
The last L lines each contain two real numbers as the coordinates of the initial
position and a name as the target port. Input is terminated with a case of N
= M = L = 0 which should not be proceeded.
You may assume:
1.Any two ports are connected via several preset paths.
2.No 2 preset paths interact except at ports.
3.All coordinated are between 0 and 1000 inclusively.
Output
For every pair of initial positon and a target port, output the length of the shortest path between them on a line of it's own. Rounded to 2 decimal places. Output a blank line after each case.
Sample Input
2 1 3 Hangzhou 1 1 Shanghai 3 1.5 Hangzhou Shanghai 0 0 Hangzhou 3 1 Hangzhou 0 0 Shanghai 4 4 2 LostTemple 1 1 TheHunters 2 3 NeoJungleStory 4 5 Rivalry 5 1 LostTemple TheHunters TheHunters NeoJungleStory NeoJungleStory Rivalry Rivalry LostTemple 0 0 NeoJungleStory 3 0 NeoJungleStory 0 0 0
Sample Output
1.41 2.43 3.48 6.48 7.12Submit
Source: ZOJ Monthly, February 2003