시간 제한 | 메모리 제한 | 제출 | 정답 | 맞은 사람 | 정답 비율 |
---|---|---|---|---|---|

3 초 | 128 MB | 5 | 2 | 2 | 40.000% |

The financial crisis in Greece has major consequences for the Greeks, especially for those who live on one of the many islands. Some of them can not even afford to travel from one island to another by boat. They avoid having to go to another island as much as possible, but if they really must, they have to swim.

Since swimming is very exhausting and potentially dangerous, they would like to minimize the distance they have to swim as much as possible. In that regard, swimming directly from island A to B may not be the best option. Instead, it might be more beneficial to swim from A to C, then cross island C on foot, before swimming from C to B. The ideal travel plan could in fact involve a lot of islands.

You are given a collection of islands, modeled as simple polygons. Determine, for two given islands, the smallest possible total distance one needs to swim in order to get from the one island to the other. The total distance covered on land is of no importance.

On the first line one positive number: the number of test cases, at most 100. After that per test case:

- one line with one integer n (2 ≤ n ≤ 50): the number of islands.
- one line with two space-separated integers s and d (1 ≤ s, d ≤ n; s ≠ d): the islands that are the start and destination of the intended journey, respectively.
- per island:
- one line with one integer m (3 ≤ m ≤ 50): the number of vertices of the polygon describing the island.
- m lines with two space-separated integers x
_{i}and y_{i}(-10 000 ≤ x_{i}, y_{i}≤ 10 000): the coordinates of the i-th vertex of the polygon.

The polygons (islands) are non-self-intersecting and do not overlap or touch each other. The vertices of the polygons are given in counterclockwise order.

Per test case:

- one line with one floating point number: the minimum distance one needs to swim in order to get from the start to the destination, rounded to three decimal places.

The test cases are such that an absolute error of at most 10^{-6} in the final answer does not influence the result of the rounding.

2 3 1 3 4 0 0 1 0 1 1 0 1 4 2 2 3 2 3 3 2 3 4 4 0 5 0 5 1 4 1 4 1 2 3 0 0 10 0 0 10 3 40 60 80 30 80 60 3 0 40 10 50 0 60 4 30 -20 40 -20 40 10 30 10

2.828 60.000

The island group as described by the second test case in the sample input. Indicated is the optimal path from the bottom left island to the top right one, which is the path that minimizes the total distance covered over water (indicated by the dashed lines).