#P8785. Mine Clearance Explosion Chain Reaction
Mine Clearance Explosion Chain Reaction
Mine Clearance Explosion Chain Reaction
You are given n bombs and m demining rockets on a two-dimensional plane. The i-th bomb is described by the triple \( (x_i, y_i, r_i) \), meaning that it is located at \( (x_i, y_i) \) and its explosion will affect all bombs whose Euclidean distance from \( (x_i, y_i) \) is at most \( r_i \) (borders included). Similarly, the j-th demining rocket is given by \( (x_j, y_j, r_j) \) and will detonate at \( (x_j, y_j) \) affecting all bombs within radius \( r_j \).
When a rocket explodes, every bomb within its explosion circle is triggered, and each triggered bomb will in turn cause a chain reaction by detonating any bomb within its own explosion range. Note that a bomb located exactly on the boundary of an explosion circle is considered to be affected.
Your task is to determine the total number of bombs detonated after all explosions and their chain reactions.
inputFormat
The first line contains two integers \( n \) and \( m \) representing the number of bombs and rockets respectively.
The next \( n \) lines each contain three numbers \( x_i \), \( y_i \), \( r_i \) (for \( 1 \le i \le n \)) describing the position and explosion radius of each bomb.
The following \( m \) lines each contain three numbers \( x_j \), \( y_j \), \( r_j \) (for \( 1 \le j \le m \)) describing the position and explosion radius of each rocket.
outputFormat
Output a single integer denoting the total number of bombs that detonate, either directly or via chain reactions.
sample
3 1
0 0 5
10 0 5
20 0 5
0 0 5
1