Slant Drilling
Time limit1sMemory limit256 MB
Choose a ground point over nested contour polygons so the straight-line distance from the surface to the pocket at the origin is shortest.
Problem
A survey map marks an oil pocket at , exactly metres above sea level. The map draws the ground with contour lines. Each contour line is a closed polygon that does not cross itself, and it comes with two heights: the height of the ground immediately outside it and the height immediately inside it. The ground between contour lines is flat, so the height at a point is the inner height of the smallest contour line containing that point. A point that no contour line contains has the outer height of a contour line that no other contour line contains, and all of those contour lines have the same outer height.
A drill starts at a point of the ground surface and reaches the pocket in a straight line. That line does not have to be vertical. Starting from a point where the ground height is , the drilled length is .
Find the shortest length that has to be drilled.
Input
The first line contains one integer , the number of contour lines.
Each of the next lines describes one contour line. The line begins with three integers , and (, ). is the height of the ground immediately outside the contour line and is the height immediately inside it, both in metres. is the number of vertices of this contour line. The rest of the line holds integers, the coordinates and () of the vertices in order along the contour line.
The vertices of one contour line are distinct and a contour line does not cross itself. No two contour lines touch, and no contour line passes through . If a contour line is contained in another one, its outer height equals the inner height of the containing contour line. The number of vertices over all contour lines is at most .
Output
Print the shortest drilled length, rounded to exactly six digits after the decimal point.