Earth Hour

**Time Limit: 2000/1000 MS (Java/others) memory limit: 125536/65536 K (Java/Others)**

Total submission (s): 1516 accepted submission (s): 606

Problem descriptionearth hour is an annual international event created by the WWF (World Wide Fund for Nature/World Wildlife Fund), held on the last Saturday of March, that asks households and businesses to turn off their non-essential lights and electrical appliances for one hour to raise awareness towards the need to take action on climate change.

To respond to the event of this year, the manager of Hunan University campus decides to turn off some street lights at night. each street light can be viewed as a point in a plane, which casts flash in a circular area with certain radius.

What's more, if two illuminated circles share one intersection or a point, they can be regarded as connected.

Now the manager wants to turn off as your lights as possible, guaranteeing that the illuminated area of the library, the study room and the dormitory are still connected (directly or indirectly ). so, at least the lights in these three places will not be turned off.

Inputthe first line contains a single integer T, which tells you there are t cases followed.

In each case:

The first line is an integer N (3 <= n <= 200), means there are n street lights at total.

Then there are n lines: each line contain 3 integers, X, Y, R, (1 <= x, y, r <= 1000), means the light in position (X, y) can illuminate a Circle area with the radius of R. note that the 1st of the N lines is corresponding to the library, the 2nd line is corresponding to the study room, and the 3rd line is corresponding to the dorm.

Outputone case per line, output the maximal number of lights that can be turned off.

Note that if none of the lights is turned off and the three places are still not connected. Just output-1.

Sample Input

351 1 11 4 14 1 12 2 13 3 171 1 14 1 12 4 11 3 13 1 13 3 14 3 161 1 15 1 15 5 13 1 25 3 23 3 1

Sample output

-121

Each lamp is regarded as a vertex that can be illuminated by each other. Calculate the shortest path from the three source points 0, 1, and 2, and then enumerate the shortest path from the three source points to each point.

# Include "stdio. H "# include" string. H "# include" queue "# include" vector "# include" algorithm "using namespace STD; # define n 205 const int INF = 1000000; int min (int A, int B) {return a <B? A: B;} struct node {int X, Y, R;} p [N]; int G [N] [N]; int d [3] [N]; int judge (int I, Int J) // determine whether two lights are intersecting {int X, Y, D, R; X = P [I]. x-P [J]. x; y = P [I]. y-P [J]. y; D = x * x + y * Y; r = P [I]. R + P [J]. r; If (R * r> = d) return 1; return 0;} void spfa (int s, int N, int * Dis) {int I, Mark [N]; memset (mark, 0, sizeof (Mark); for (I = 0; I <n; I ++) dis [I] = inf; DIS [s] = 0; queue <int> q; q. push (s); Mark [s] = 1; while (! Q. empty () {S = Q. front (); q. pop (); Mark [s] = 0; for (I = 0; I <n; I ++) {If (DIS [I]> dis [s] + G [s] [I]) {dis [I] = dis [s] + G [s] [I]; if (! Mark [I]) {mark [I] = 1; q. push (I) ;}}}} int main () {int T, I, j, X, Y, R, N; scanf ("% d ", & T); While (t --) {scanf ("% d", & N); for (I = 0; I <n; I ++) {scanf ("% d", & X, & Y, & R); P [I]. X = x; P [I]. y = y; P [I]. R = r ;}for (I = 0; I <n; I ++) {G [I] [I] = 0; For (j = 0; j <I; j ++) {If (Judge (I, j) g [I] [J] = G [J] [I] = 1; else G [I] [J] = G [J] [I] = inf ;}} spfa (0, N, d [0]); spfa (1, n, d [1]); spfa (2, N, d [2]); int ans = inf; for (I = 0; I <n; I ++) {ans = min (ANS, d [0] [I] + d [1] [I] + d [2] [I]);} If (ANS <inf) printf ("% d \ n", n-ans-1); else printf ("-1 \ n");} return 0 ;}