Clock

Interview

Time limit1sMemory limit128 MB

Summary
Find the largest empty circle fully inside a rectangular wall that avoids up to 50 non-overlapping discs, using a generalized Voronoi diagram of points, segments, and circles.
Level

Hard8 of 10

Topics
Geometry, Divide and conquer, Sorting, Math
Solved
No attempts yet

Problem

Heewon collects round wall clocks and has hung all of them on a single wall in the living room. He now wants to buy one more clock and hang it in the empty space, without moving any of the clocks that are already on the wall. He wants the largest possible round clock that can still be hung.

The wall is a rectangle of width WW and height HH. Each hanging clock is a circle with center (xi,yi)(x_i, y_i) and radius rir_i. The existing clocks stay within the wall and never overlap one another (though they may touch).

The new clock is also a circle. It must lie entirely within the wall and must not overlap any existing clock (touching is allowed). Find the largest radius of such a clock. This maximum radius is uniquely determined.

Input

The first line contains the number of test cases TT.

Each test case is given as follows.

  • The first line contains the width and height of the wall, WW and HH. (1≤W,H≤1061 \le W, H \le 10^6)
  • The second line contains the number of clocks hanging on the wall, CC. (0≤C≤500 \le C \le 50)
  • Each of the next CC lines contains one clock's data xix_i, yiy_i, rir_i. (ri>0r_i > 0, 0≤xi−ri0 \le x_i - r_i, xi+ri≤Wx_i + r_i \le W, 0≤yi−ri0 \le y_i - r_i, yi+ri≤Hy_i + r_i \le H)

Every pair of distinct clocks ii, jj (i≠ji \ne j) satisfies (xi−xj)2+(yi−yj)2≥(ri+rj)2(x_i - x_j)^2 + (y_i - y_j)^2 \ge (r_i + r_j)^2.

Output

For each test case, print on its own line the radius of the largest clock that can be hung, rounded to six digits after the decimal point.

Examples3

  1. Example 1

    Input
    1
    10 10
    4
    2 2 1
    2 8 1
    8 2 1
    8 8 1
    
    Expected output
    3.242641
    
  2. Example 2

    Input
    1
    10 10
    0
    
    Expected output
    5.000000
    
  3. Example 3

    Input
    1
    1 1
    0
    
    Expected output
    0.500000