This page is still under construction.

Parts of this page are still being built. What you see may change.

Sneaking Through the Corridor

Time limit5sMemory limit256 MB

Summary
Find the largest radius of a circle that can travel between two walls past circular sensors without entering any range.
Level

Medium7 of 10

Topics
Union-find, Geometry, Binary search
Solved
No attempts yet

Problem

Seunghyun keeps his room under tight security. The only way in runs along a corridor packed with sensors, and a sensor sounds the alarm as soon as a person or an object enters its range.

Hyunseok is a very nimble spy. A client hired him to steal a classified document from Seunghyun's room, so he got hold of the corridor blueprint first. From the blueprint he has to decide whether he can walk in himself, and if he cannot, how small a robot he has to send instead.

Hyunseok treats the corridor as a plane. The two walls are the lines x=0x = 0 and x=wx = w, and sensor ii detects everything inside the circle with center (xi,yi)(x_i, y_i) and radius rir_i. A sensor sits against a wall or in the middle of the corridor. The object that travels down the corridor is a circle as well.

The object starts at y=−∞y = -\infty and has to reach y=+∞y = +\infty while staying inside the corridor. It must never enter the detection range of a sensor. Touching the boundary of a range is fine.

Given the sensor layout, find the largest radius of a circle that gets through the corridor without setting off an alarm.

Input

The first line has the number of test cases TT. (1≤T≤1001 \le T \le 100)

Each test case has this form.

  • One line with the corridor width ww. (1≤w≤100 0001 \le w \le 100\,000) The two walls are the lines x=0x = 0 and x=wx = w.
  • One line with the number of sensors nn. (0≤n≤1 0000 \le n \le 1\,000)
  • nn lines with integers xx, yy, rr, the center of a sensor and the radius of its range. (0≤x≤w0 \le x \le w, −100 000≤y≤100 000-100\,000 \le y \le 100\,000, 1≤r≤100 0001 \le r \le 100\,000)

The corridor runs forever along yy, and the end the object starts from and the end it leaves through are both far outside every sensor range.

Output

For each test case print on its own line the largest radius of a circular object that passes the corridor undetected. Assume the object moves with unlimited precision. Print 00 when nothing can get through.

Round the answer to six decimal places and always print all six digits after the point. An answer of 1.51.5 prints as 1.500000, and an answer of 00 prints as 0.000000.

Examples1

  1. Example 1

    Input
    3
    10
    2
    2 0 3
    7 12 4
    10
    2
    2 0 3
    7 8 4
    10
    2
    2 0 3
    7 4 4
    
    Expected output
    1.500000
    1.216991
    0.000000