Mines
Time limit1sMemory limit128 MB
Trigger the fewest mines so chain reactions through overlapping blast squares detonate all N mines.
- Level
Medium7 of 10
- Topics
- Graph, DFS, Topological sort
- Solved
- No attempts yet
Problem
There are mines buried in an old battlefield. Each mine affects an axis-parallel square area determined by its performance. Treat the mine's location as the center of that square area. When a mine explodes, every mine whose center lies inside the exploding square area also explodes. By chain reaction, the mines inside the square areas of those newly exploded mines explode as well.
A mine lying exactly on the boundary of an exploding square area also explodes. In the figure below, if mine 4 is triggered first, mines 3 and 6 explode. If mine 1 is triggered first, mine 4 explodes, and the following blast makes mines 3 and 6 explode too. Therefore, triggering mines 1, 2, and 5 causes every mine to explode.

Given mines on a two-dimensional plane, each with its explosion performance described as a square area, write a program that finds the minimum number of mines you must trigger directly so that all mines explode.
Input
The input is read from standard input. It consists of test cases. The first line contains the number of test cases . Each test case begins with a line containing the number of mines (). Each of the next lines contains three integers , , and , where and are the coordinates of the mine and is the side length of the square that represents its explosion performance (, ). Since the square is centered at with side length , the distance from the center to each side is .
Output
Write the result to standard output. For each test case, print exactly one line containing the minimum number of mines that must be triggered directly so that all mines explode.