var
n,d,i,j,a,b,m:longint;
s:char;
x,y,f:array[1..1001] of longint;
used:array[1..1001] of boolean;
w:array[1..1001,1..1001] of real;
function findset(x:longint):longint;
begin
if x<>f[x] then
f[x]:=findset(f[x]);
exit(f[x]);
end;
procedure union(x,y:longint);
begin
x:=findset(x);
y:=findset(y);
if x<>y then
f[x]:=y;
end;
begin
fillchar(f,sizeof(used),0);
fillchar(x,sizeof(x),0);
fillchar(y,sizeof(y),0);
fillchar(used,sizeof(used),false);
read(n,d);
for i:=1 to n do
begin
read(x[i],y[i]);
f[i]:=i;
end;
for i:=1 to n do
for j:=i to n do
begin
w[i,j]:=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
w[j,i]:=w[i,j];
end;
while not eof do
begin
read(s);
cases of
'S':begin
read(a,b);
if findset(a)=findset(b)then
writeln('SUCCESS')
else
writeln('FAIL');
end;
'O':begin
read(m);
used[m]:=true;
for i:=1 to n do
if (w[i,m]<=d) and(used[i]) then
union(m,i);
end;
end;
end;
end.
poj2236 wireless network并查集
最新推荐文章于 2019-08-10 18:07:58 发布