Island Travel
Time limit2sMemory limit1024 MB
Find the minimum flying distance from island a to island b, where Hiccup can walk freely across each convex polygon island.
- Level
Medium7 of 10
- Topics
- Shortest path, Geometry
- Solved
- No attempts yet
Statement
Hiccup and Toothless find themselves in the middle of an archipelago. The archipelago has islands. Seen from a bird's-eye view, each island is a convex polygon. No two islands share a point. The islands are numbered from to . Hiccup is on island and urgently needs to reach island .
Hiccup and Toothless can walk freely on any island. To get from one island to another, Toothless has to fly. Toothless can take off from any point on any island, fly along any route, and land at any point on any island. The distance he flies equals the length of that route. Toothless is very tired, so Hiccup wants to minimize the distance Toothless flies. Help him find this distance.
Input
The first line contains three integers , , and : the number of islands, the island where Hiccup starts, and the island where he wants to go (, ).
Each island description starts with an integer , the number of vertices of the polygon for the -th island (). The next lines each contain two integers and , the coordinates of the -th vertex of the -th polygon (). Vertices are given in counterclockwise order. No three consecutive vertices lie on one line.
The islands are numbered from to in the order they appear in the input. It is guaranteed that no two polygons share a point.
Output
Print one real number: the minimum distance Toothless must fly so that Hiccup can get from island to island . The answer is accepted if its absolute or relative error does not exceed .
Hint
The first figure shows the part of the route that Hiccup and Toothless walk in orange, and the part that Toothless flies in blue.

The second figure is shown below.
