版权声明:菜鸟一枚~~ 有想法可在下面评论, 转载标明出处即可。 https://blog.csdn.net/KLFTESPACE/article/details/87609796
//读取C的时候没有!=EOF 会出现TLE的错误.....
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 10000+5;
pair<int, int> a[N];
int pre[N], store[N];
int map[N][N];
int n, k;
void init()
{
for(int i=0; i<=N; i++){
pre[i] = i;
}
}
bool JudgeDist(int c, int b)
{
int dx = a[c].first - a[b].first;
int dy = a[c].second - a[b].second;
/*
int length = (dx*dx+dy*dy);
cout << "X :" << a[c].first << " " << a[b].first << endl;
cout << "Y :" << a[c].second << " " << a[b].second << endl;
cout << "dist :" << length << ":" << k << endl;
*/
return (dx*dx+dy*dy) <= k*k;
}
int Find(int a)
{
return (pre[a]==a) ? a : Find(pre[a]);
}
/*
int Find(int x)//查询
{
while(pre[x] != x)
x = pre[x];
return x;
}
*/
void Union(int a, int b)
{
a = Find(a);
b = Find(b);
if(a != b)
pre[b] = a;
// pre[Find(b)] = Find(a);
}
int main()
{
cin >> n >> k;
for(int i=1; i<=n; i++){
cin >> a[i].first >> a[i].second;
}
getchar();
init();
char c;
int i = 0;
while(~(c = getchar())){
if(c == 'O'){
int tmp;
cin >> tmp;
store[i++] = tmp;
for(int j=0; j<i-1; j++){
// cout << store[j] << endl;
if(JudgeDist(store[j], tmp)){
Union(store[j], tmp);
// cout << "Find:" << Find(store[i]) << " " << Find(tmp) << endl;
}
}
}
else if(c == 'S'){
int a, b;
cin >> a >> b;
// cout << Find(a) << " " << Find(b) << endl;
if(Find(a) == Find(b))
cout<<"SUCCESS"<<endl;
else
cout<<"FAIL"<<endl;
}
getchar();
}
return 0;
}