eolymp
bolt
Try our new interface for solving problems
Problems

Blue Forest

Blue Forest

John is playing a famous console game named `Tales of Algorithmers.' Now he is facing the last dungeon called `Blue Forest.' To nd out the fastest path to run through the very complicated dungeon, he tried to draw up the dungeon map. The dungeon consists of several floors. Each oor can be described as a connected simple plane graph. Vertices of the graph are identi ed by \textbf{X}-\textbf{Y} coordinate, and the length of an edge is calculated by Euclidean distance. A vertex may be equipped with a one-way warp gate. If John chooses to use the gate, it brings John to another vertex in a possibly di erent floor. The distance between a warp gate and its destination is considered as \textbf{0}. One vertex has at most one warp gate, though some vertices might be the destination of multiple warp gates. He believed he made one map for each floor, however after drawing maps of all the floors, he noticed that he might have made a few mistakes. He might have drawn the same floor several times, and might have forgotten to mark some warp gates in the maps. However, he was sure he marked all warp gates at least once. So if the maps of same floor are uni ed to one map, all the warp gates must be described there. Luckily there are no floors which have the same shape as the other floors, so if two (or more) maps can be uni ed, they must be the maps of the same floor. Also, there is no floor which is circular symmetric (e.g. a regular triangle and a square). Map \textbf{A} and map \textbf{B} can be uni ed if map \textbf{B} can be transformed to map \textbf{A} using only rotation and parallel translation. Since some of the warp gates on maps might be missing, you should not consider the existence of warp gates when checking uni cation. If it is possible to unify map \textbf{A} and map \textbf{B}, a vertex on map A and the corresponding vertex on map B are considered as 'identical' vertices. In other words, you should treat warp gates on map \textbf{B} as those on map \textbf{A} where the warp gates are located on the corresponding vertices on map \textbf{A}. Destinations of warp gates should be treated similarly. After that you can forget map \textbf{B}. It is guaranteed that if both map \textbf{A} and map \textbf{B} have warp gates which are on the identical vertices, the destinations of them are also identical. Remember, your task is to nd the shortest path from the entrance to the exit of the dungeon, using the uni ed maps. \InputFile The input consists of multiple datasets. Each dataset is in the following format. \textbf{n component_1 component_2 ... component_n sl sn dl dn} \textbf{n} is a positive integer indicating the number of maps. componenti describes the \textbf{i}-th map in the following format. \textbf{A x_1 y_1 x_2 y_2 ... x_A y_A B s_1 d_1 s_2 d_2 ... s_B d_B C sn_1 dl_1 dn_1 sn_2 dl_2 dn_2 ... sn_C dl_C dn_C} A denotes the number of vertices in the map. Each of the following \textbf{A} lines contains two integers \textbf{x_i} and \textbf{y_i} representing the coordinates of the \textbf{i}-th vertex in the \textbf{2}-dimensional plane. \textbf{B} denotes the number of the edges connecting the vertices in the map. Each of the following \textbf{B} lines contains two integers representing the start and the end vertex of each edge. Vertices on the same map are numbered from \textbf{1}. \textbf{C} denotes the number of warp gates. Each of the following \textbf{C} lines has three integers describing a warp gate. The first integer is the vertex where the warp gate is located. The second and the third integer are the indices of the map and the vertex representing the destination of the warp gate, respectively. Similarly to vertices, maps are also numbered from \textbf{1}. After the description of all maps, two lines follow. The first line contains two integers \textbf{sl} and \textbf{dl}, meaning that the entrance of the dungeon is located in the \textbf{sl}-th map, at the vertex \textbf{dl}. The last line has two integers \textbf{sn} and \textbf{dn}, similarly describing the location of the exit. The values in each dataset satisfy the following conditions: \begin{itemize} \item \textbf{1} ≤ \textbf{n} ≤ \textbf{50}, \item \textbf{3} ≤ \textbf{A} ≤ \textbf{20}, \item \textbf{A-1} ≤ \textbf{B} ≤ \textbf{A(A-1)/2}, \item \textbf{0} ≤ \textbf{C} ≤ \textbf{A}, and \item \textbf{-10000} ≤ \textbf{x_i}, \textbf{y_i} ≤ \textbf{10000}. \end{itemize} \OutputFile For each dataset, print the distance of the shortest path from the entrance to the exit. The output should not contain an absolute error greater than \textbf{10^\{-1\}}. If there is no route, print \textbf{-1}.
Time limit 30 seconds
Memory limit 256 MiB
Input example #1
2
5
0 0
10 0
20 0
30 0
30 10
4
1 2
2 3
3 4
4 5
2
1 2 4
3 2 2
5
-10 0
0 0
0 -10
0 -20
0 -30
4
1 2
2 3
3 4
4 5
1
4 1 3
1 1
2 1
4
3
4 3
0 0
5 0
2
1 2
2 3
0
3
0 0
3 4
0 5
2
1 2
1 3
1
2 3 4
4
0 13
0 0
13 0
13 13
4
1 2
1 4
2 3
2 4
0
4
5 12
0 0
-7 17
-12 5
4
1 2
2 3
2 4
4 3
0
1 1
4 1
4
3
0 0
2 0
0 4
2
1 2
1 3
0
3
0 0
-2 0
0 4
2
1 2
1 3
1
1 4 1
3
0 0
1 0
0 2
2
1 2
1 3
1
1 4 1
3
0 0
2 0
0 4
2
1 2
2 3
0
1 1
4 1
0
Output example #1
10.0000000000
41.3847763109
-1.000000000
Source ACM International Collegiate Programming Contest JAG Practice Contest, Tokyo, 2011-11-06