-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2236.cpp
93 lines (87 loc) · 1.47 KB
/
2236.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <cstdio>
using namespace std;
template <int max_size>
struct u_set{
struct tree{
int father;
}tr[max_size];
void init(int size)
{
for (int i = 1; i <= size; ++ i)
tr[i].father = i;
}
int find(int x)
{
if (x == tr[x].father)
return x;
tr[x].father = find(tr[x].father);
return tr[x].father;
}
void merge(int temp1, int temp2)
{
int a = find(temp1);
int b = find(temp2);
if (a != b)
{
tr[a].father = b;
}
}
};
u_set<1010> t;
struct point{
int x;
int y;
bool isrepaired;
}pos[1010];
int main()
{
int n, d;
scanf("%d %d", &n, &d);
{
t.init(n);
for (int i = 1; i <= n; ++ i)
{
scanf("%d %d", &pos[i].x, &pos[i].y);
}
char s[10];
while (~scanf("%s", s))
{
if (s[0] == 'O')
{
int temp1;
scanf("%d", &temp1);
// cout << temp1 << endl;
pos[temp1].isrepaired = true;
for (int i = 1; i <= n; ++ i)
{
if (pos[i].isrepaired && (pos[i].x - pos[temp1].x) * (pos[i].x - pos[temp1].x) + (pos[i].y - pos[temp1].y) * (pos[i].y - pos[temp1].y) <= d * d)
{
// cout << i << endl;
t.merge(i, temp1);
}
}
// cout << endl;
}
else if (s[0] == 'S')
{
int temp1, temp2;
scanf("%d %d", &temp1, &temp2);
int a = t.find(temp1);
int b = t.find(temp2);
// cout << " a";
// cout << a << endl;
// cout << b << endl;
if (a == b)
{
printf("SUCCESS\n");
}
else
{
printf("FAIL\n");
}
}
}
}
return 0;
}