It's a matter of counting and checking.
Test instructions is said to have n computers, each computer can be self-centered connected to the D-meter range of computers.
Give the coordinates of the n computer, for the inquiry operation, the output is connected.
I use adjacency table to store, if two computer coordinates distance less than their radius and, save up, indicating that these two points can be connected.
Use online[] to indicate whether it has been repaired. After the repair, you can use and check the collection merge.
The repair operation enables online and then iterates through the neighboring edges of the point, and if there are online, merge.
Then it is for the query output. In a collection, success.
#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <queue> #include <map> #include <stack> #include <iostream> #include <list># include<set> #include <cmath> #define INF 0x7fffffff#define eps 1e-6using namespace std;int n;double r;vector <int>g[1001];int fa[1001];bool online[1001];struct node{double x, y;} point[1001];int father (int x) {if (x!=fa[ X]) return Fa[x]=father (Fa[x]);} Double Getlen (node A,node b) {double len=sqrt (POW (a.x-b.x,2) +pow (a.y-b.y,2)); return len-r;} int main () {scanf ("%d%lf", &n,&r); for (int i=1; i<=n; i++) scanf ("%lf%lf", &point[i].x,&point[i].y); for (int i=1; i<=n; i++) fa[i]=i,g[i].clear (); int cot=0; for (int i=1, i<=n; i++) for (int j=i+1; j<=n; J + +) {double Len=getlen (point[i],point[j]); if (len<=0) {g[i].push_back (j); G[j].push_back (i); }} memset (Online,0,sizeof (online)); Char str[10]; while (scanf ("%s", str)!=eof) {if (str[0]== ' s ') {int A, B; scanf ("%d%d", &a,&b); if (father (a)!=father (b)) puts ("FAIL"); Else puts ("SUCCESS"); } else if (str[0]== ' O ') {int u; scanf ("%d", &u); Online[u]=1; for (int j=0; j<g[u].size (); j + +) {int v=g[u][j]; if (!online[v]) continue; V=father (v); if (u==v) continue; Fa[v]=u; } } }}