poj2236 wireless network并查集

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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值