Mission Impossible

Time limit3sMemory limit128 MB

Summary
Given a simple polygon border, radar disks that block movement, and informers inside, decide which reachable informer lies farthest from the border, starting from (2000, 2000).
Level

Hard8 of 10

Topics
Geometry, Union-find, Graph, Implementation
Solved
No attempts yet

Problem

You have been hired to explore enemy territory, a risky business. The enemy has placed several radar stations across the country; each radar instantly destroys any moving vehicle within its circular range of coverage.

Fortunately, your government has given you a map of the enemy territory: the coordinates and coverage radius of every radar. You also have a list of local informers and their locations. Your mission is to contact one informer, preferably the one with the highest insider-coefficient.

The insider-coefficient of an informer is the distance from that informer to the border of the country, that is, the minimum distance from the informer's location to any point on the border. Intuitively, the informer with the highest insider-coefficient is located as deep inside the country as possible, and is presumed to hold the most valuable information.

Write a program that decides whether there is a path from your starting location, always the point (2000,2000)(2000, 2000), to some informer's location, without ever entering a region covered by a radar. Whenever such a path exists, the program must also report which reachable informer should be contacted, according to the insider-coefficient criterion above.

Figure 1: A possible scenario

The enemy country has the shape of a simple polygon (not necessarily convex); a polygon is simple when its boundary is a single, non-self-intersecting loop. The border is given as the sequence of vertices of the polygon. Every radar centre and every informer lies inside the border, but a radar's coverage may extend outside the border.

In Figure 1, informer I1I_1 cannot be contacted because he lies inside a radar-covered region. Informer I2I_2, although outside every radar region, cannot be contacted either, because any route to him would pass through a deadly radar-covered region. Both I3I_3 and I4I_4 can be contacted, so I4I_4 is chosen because his insider-coefficient is greater than that of I3I_3.

Input

The input consists of several test cases. The first line of each test case describes the border of the enemy country:

B X1 Y1 X2 Y2 ... XB YB

where 3≤B≤10003 \le B \le 1000 is the number of border points and each Xi YiX_i\,Y_i is the coordinate of the ii-th border point. The border consists of the segments between points ii and i+1i+1, and between points BB and 11.

The second line gives the informers:

N X1 Y1 X2 Y2 ... XN YN

where 1≤N≤10001 \le N \le 1000 is the number of informers and Xi YiX_i\,Y_i is the location of the ii-th informer.

The third line describes the radars:

M X1 Y1 R1 X2 Y2 R2 ... XM YM RM

where 1≤M≤301 \le M \le 30 is the number of radars, Xi YiX_i\,Y_i is the centre of the ii-th radar, and RiR_i is its radius.

All coordinates are integers with 0≤X,Y≤10000 \le X, Y \le 1000, and every radius is an integer with 1≤R≤10001 \le R \le 1000. A test case with B=N=M=0B = N = M = 0 marks the end of the input and must not be processed. Every radar centre and every informer lies inside the border, but the area covered by the radars may extend outside it.

Output

For each test case, print one line containing either Mission impossible or Contact informer K, where K is the input index of the reachable informer with the highest insider-coefficient. If several reachable informers share the highest insider-coefficient, choose the one with the smallest index.

Examples3

  1. Example 1

    Input
    4 0 0 0 200 200 200 200 0
    2 70 70 120 120
    1 100 100 100
    4 0 0 0 200 200 200 200 0
    3 100 102 70 80 20 10
    4 70 70 35 130 70 35 130 130 35 70 130 35
    0
    0
    0
    
    Expected output
    Mission impossible
    Contact informer 3
    
  2. Example 2

    Input
    4 0 0 200 0 200 200 0 200
    1 50 50
    0
    0 0 0
    
    Expected output
    Contact informer 1
    
  3. Example 3

    Input
    4 0 0 200 0 200 200 0 200
    2 10 100 100 100
    0
    0 0 0
    
    Expected output
    Contact informer 2