Keep in Touch
Time limit1sMemory limit1024 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
Two agents, A and B, are known as a great combination. They are carrying out an infiltration mission to a secret base. Because the base has strict security, the two agents have decided to follow the prechecked safe infiltration routes and , respectively. Each route is a two-dimensional polyline, a series of line segments.
Each agent starts at the starting end of the first segment of its route. The mission is over when both agents are on the finishing ends of the last segments of their routes at the same time.
During the mission, each agent can move forward or backward at any speed, or stop for a moment, as long as its movement along the route is continuous. An agent cannot jump to a new position. Segments may cross or overlap, but they cannot be used for movement. Precisely, an agent on one segment can move to another segment only in these cases.
- The destination is the next segment on the route, and the agent is at the finishing end of the current segment.
- The destination is the previous segment on the route, and the agent is at the starting end of the current segment.
For example, in Figure G-1, the agent must reach the finishing end of segment 3-4 of , which is , before it can move to segment 4-5. When the agent moves from segment 2-3 to segment 3-4, it passes , the finishing end of the last segment. That passage does not count, because the agent is not considered to be at the finishing end of the last segment at that time.

Figure G-1: Infiltration routes for the first dataset

Figure G-2: Infiltration routes for the second dataset
The two agents must always stay within communication range of each other. A stronger signal allows a longer communication distance, but it also raises the chance of interception. Find the minimum communication distance that lets the agents complete the mission with suitable movements.
Input
The input consists of multiple datasets, each in the following format.
n
xA,1 yA,1
⋮
xA,n yA,n
m
xB,1 yB,1
⋮
xB,m yB,m
is the number of vertices of route . is an integer from 2 to 40, inclusive.
and () are the coordinates of the -th vertex. They are integers satisfying and . For , is the starting end of the -th segment, and is its finishing end. Every segment has nonzero length, so or holds.
and the pairs and () describe route . The format and constraints are the same as for .
The input ends with a line containing 0.
Output
For each dataset, print on one line the maximum distance between the two agents during the mission, when the agents move so that this maximum is as small as possible. The error must not exceed . An answer is accepted if either its relative error or its absolute error is within this limit.