#P2778. [AHOI2016初中组] 迷宫

[AHOI2016初中组] 迷宫

Description

Xiaoxue and Xiaokeke are trapped in an infinite maze.

It is known that this maze has NN ring-shaped walls. If we regard the entire maze as a 2D plane, then each wall is a circle on the plane. Any two circles do not intersect, do not coincide, and are not tangent, but they may contain each other. Xiaoxue and Xiaokeke are trapped at two different positions, and it is guaranteed that their positions do not lie on any of these circles.

They can pass through only by breaking the walls.

Xiaoxue wants to know the minimum number of walls they need to break in order to meet. They may meet at any location.

Input Format

The first line contains an integer NN, the number of walls.

The next NN lines each contain three integers x,y,rx, y, r, indicating a ring-shaped wall that is a circle centered at (x,y)(x, y) with radius rr.

The next line contains an integer QQ, the number of queries.

The following QQ lines each contain four integers a,b,c,da, b, c, d, representing one query: Xiaoxue is at position (a,b)(a, b), and Xiaokeke is at position (c,d)(c, d).

Output Format

Output QQ lines, one per query. For each query, output one integer: the minimum number of walls that must be broken for them to meet.

3
0 0 1
3 0 1
2 0 4
1
0 0 3 0
2
3
0 0 1
0 0 2
4 0 1
2
0 0 4 0
0 0 0 4
3
2

Hint

For 20%20\% of the testdata, 0N2000\le N\le 200.

For 40%40\% of the testdata, 0N10000\le N\le 1000.

For 100%100\% of the testdata, $0\le N, Q\le 8000,-10^8\le x,y,r, a, b, c, d\le 10^8$.

In addition, there is an extra 20%20\% of the testdata with 0N1000,0Q10000\le N\le 1000, 0\le Q\le 1000.

Large testdata time limit: 3 s\rm 3\ s.

Translated by ChatGPT 5