#P2778. Escape Maze Walls

    ID: 16040 Type: Default 1000ms 256MiB

Escape Maze Walls

Escape Maze Walls

Two friends, Xiaoxue and Xiaokeke, are trapped in an infinitely large maze. The maze has \(N\) circular walls. Each wall is a circle on a 2D plane. Any two circles do not intersect, coincide, or touch; however, they may be nested (one completely contained within another).

The two friends are trapped at two distinct positions, and it is guaranteed that neither position lies exactly on any of the circles. They can only pass through the maze by breaking the walls.

They want to meet at some position (which can be chosen arbitrarily) with the minimum number of wall-breaks. Determine the minimum number of walls that must be broken in order for them to meet.

Hint: For each wall (circle), if one friend is inside and the other is outside, then that wall has to be crossed (i.e. broken). Consequently, the answer is the number of circles for which exactly one of the friends is inside.

Mathematical Formulation:

For a circle with center \((x, y)\) and radius \(r\), a point \((p, q)\) is inside the circle if and only if:

\[ (p-x)^2+(q-y)^2

inputFormat

The first line contains an integer \(N\) representing the number of circular walls in the maze. \( (1 \leq N \leq 10^5) \)

The next \(N\) lines each contain three space-separated integers \(x\), \(y\), and \(r\) which denote the center coordinates and the radius of a circle.

The last line contains four space-separated integers: \(x_1\), \(y_1\), \(x_2\), \(y_2\), representing the positions of Xiaoxue and Xiaokeke respectively. It is guaranteed that neither position lies exactly on any circle.

outputFormat

Output a single integer indicating the minimum number of walls that must be broken for the two friends to meet.

sample

3
0 0 15
0 0 10
0 0 5
2 2 11 11
3