1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
| #include<stdio.h>
#include<math.h>
#include<string.h>
int par[1020];
int rank[1020];
int find(int m) {
if(par[m]==m)
return m;
else {
return par[m]=find(par[m]);
}
}
void unite(int x,int y) {
x=find(x);
y=find(y);
if(x==y)
return;
else {
if(rank[x]<rank[y]) {
par[x]=y;
} else {
par[y]=x;
if(rank[x]==rank[y]) {
rank[x]++;
}
}
}
}
int main() {
int N,D;
scanf("%d %d",&N,&D);
int xy[1020][2];
int flag[1020];
memset(flag,0,sizeof(flag));
for(int i=1; i<=N; i++) {
par[i]=i;
rank[i]=0;
}
for(int i=1; i<=N; i++) {
scanf("%d %d",&xy[i][0],&xy[i][1]);
}
char c;
getchar();
while(scanf("%c",&c)!=EOF) {
if(c=='O') {
int t;
scanf("%d",&t);
flag[t]=1;
for(int i=1; i<=N; i++) {
if(flag[i]==1&&i!=t) {
if((xy[i][0]-xy[t][0])*(xy[i][0]-xy[t][0])+(xy[i][1]-xy[t][1])*(xy[i][1]-xy[t][1])<=D*D) {
unite(i,t);
}
}
}
} else if(c=='S') {
int p1,p2;
scanf("%d %d",&p1,&p2);
if(find(p1)==find(p2)) {
printf("SUCCESS\n");
} else
printf("FAIL\n");
}
getchar();
}
return 0;
}
|