Flight Safety
Time limit1sMemory limit128 MB
Given a flight polyline and continent polygons, compute the maximum over all points on the route of the minimum distance to any continent boundary or interior.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search, Brute force
- Solved
- No attempts yet
Problem
Safety is a crucial concern when planning flights. First and foremost, one should of course take every possible measure to make sure that the trip is uneventful and that no incidents occur. But even then, one should always be prepared for the worst and try to make sure that, if an incident does happen, people's chances of survival are as high as possible.
When making an emergency landing over water, the distance to the nearest land is a critical factor. In general, the further out on the open water you are, the worse the odds of survival. Thus, an important safety parameter of a flight is how far away from the nearest land any part of the flight will take you. Your job is to write a program that, given a flight route, determines this distance.
To simplify matters, we model the world as a 2-dimensional plane rather than a sphere. We model continents as polygons and a flight route as a sequence of key points connected by straight line segments. A flight route always starts and ends strictly inside a continent, but intermediate key points may lie over water. Continents do not intersect themselves and do not touch each other.

The figure shows the second sample case; the point furthest from land is marked with a square.
Input
The first line contains one positive integer: the number of test cases, at most 100. Each test case is then given as follows:
- One line containing two integers () and (), where is the number of continents and is the number of key points in the flight route.
- lines, each containing two integers , giving the coordinates of the key points, from first to last.
- The descriptions of the continents. Each continent description starts with a line containing an integer () giving the number of vertices of that continent. It is followed by lines, each containing two integers , giving the coordinates of the vertices, in either clockwise or counter-clockwise order.
Every coordinate in the input is between and .
Output
For each test case, print one line containing the greatest distance from land that the flight route reaches.
Print this value with exactly six digits after the decimal point (for example, using printf("%.6f", answer)).