#include<iostream>
#include<cmath>
#include<string>
using namespace std;
const int MAX=1010;
int pre[MAX];
int used[MAX];
void init(int n){
for(int i=1;i<=n;i++){
pre[i]=i;
used[i]=0;
}
}
int find(int x){
if(pre[x]==x) return x;
return pre[x]=find(pre[x]);
}
void unite(int x,int y){
x=find(x);
y=find(y);
if(x==y) return;
pre[x]=y;
}
bool same(int x,int y){
return find(x)==find(y);
}
double dx[MAX],dy[MAX];
double dist(int p1,int p2){
return sqrt((dx[p1]-dx[p2])*(dx[p1]-dx[p2])+(dy[p1]-dy[p2])*(dy[p1]-dy[p2]));
}
int n;
double d;
int main(){
ios::sync_with_stdio(false);
cin>>n>>d;
for(int i=1;i<=n;i++){
cin>>dx[i]>>dy[i];
}
init(n);
string cmd;
while(cin>>cmd){
if(cmd=="O"){
int p;
cin>>p;
used[p]=1;
for(int i=1;i<=n;i++){
if(used[i]&&dist(i,p)<=d)
unite(i,p);
}
}
else{
int p1,p2;
cin>>p1>>p2;
if(same(p1,p2)) cout<<"SUCCESS"<<endl;
else
cout<<"FALL"<<endl;
}
}
return 0;
}
poj2236Wireless Network
最新推荐文章于 2020-07-21 14:39:56 发布