forked from yogykwan/acm-challenge-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoj2236.cpp
64 lines (57 loc) · 1.43 KB
/
poj2236.cpp
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
/*
* POJ 2236: Wireless Network
* 题意:给出多台损坏的电脑的坐标,任意两台修好且距离不超过d的电脑可以连线。给出修复某些电脑的指令,随时确认给出某两台之间是否有通路。
* 类型:并查集
* 算法:修复某台电脑时,将已修复的电脑中距离符合的和当前电脑所在的集合合并。判断是否有通路找到各自的集合代表元素看是否相同即可。
*/
#include <iostream>
#include <cstdio>
using namespace std;
int x[1010], y[1010];
int fa[1010];
bool fxd[1010];
int n, d;
bool close(int a, int b) {
return d * d - (x[a] - x[b]) * (x[a] - x[b]) >= (y[a] - y[b]) * (y[a] - y[b]);
}
int find(int a) {
if(fa[a] != a) {
fa[a] = find(fa[a]);
}
return fa[a];
}
void merge(int a, int b) {
fa[find(a)] = find(b);
}
int main() {
scanf("%d%d", &n, &d);
for(int i = 1; i <= n; ++i) {
scanf("%d%d", &x[i], &y[i]);
fa[i] = i;
}
char op[5];
int a, b;
while(scanf("%s", op) != EOF) {
if(op[0] == 'O') {
scanf("%d", &a);
if(!fxd[a]) {
fxd[a] = true;
for(b = 1; b <= n; ++b) {
if(!fxd[b]) continue;
if(find(a) == find(b)) continue;
if(close(a, b)) {
merge(a, b);
}
}
}
} else {
scanf("%d%d", &a, &b);
if(find(a) == find(b)) {
printf("SUCCESS\n");
} else {
printf("FAIL\n");
}
}
}
return 0;
}