#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <stack>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
int n,d;
int fat[1111],rel[1111];
int lx[1111],ly[1111];
void init(){
for(int i = 0;i<n;i++)
fat[i] = i;
}
int findf(int x){
if(fat[x]!=x)
fat[x] = findf(fat[x]);
return fat[x];
}
void unio(int x,int y){
fat[findf(x)] = findf(y);
}
double dis(int a,int b){
return sqrt(double(lx[a]-lx[b])*(lx[a]-lx[b])+(ly[a]-ly[b])*(ly[a]-ly[b]));
}
int main(){
cin>>n>>d;
for(int i = 0;i<n;i++) cin>>lx[i]>>ly[i];
init();
string str;
int t1, t2,len = 0;
while(cin>>str){
switch(str[0]){
case 'O':
cin>>t1;
t1--;
rel[len++] = t1;
for(int i = 0;i<len-1;i++)
if(rel[i]!=t1&&dis(t1,rel[i])<=d)
unio(rel[i],t1);
break;
case 'S':
cin>>t1>>t2;
if(findf(t1-1) == findf(t2-1))
cout<<"SUCCESS"<<endl;
else
cout<<"FAIL"<<endl;
break;
default:
break;
}
}
return 0;
}
poj 2236
最新推荐文章于 2024-06-13 10:13:20 发布