记录编号 15281 评测结果 AAAAAAAAAA
题目名称 [USACO Dec07] 建造路径 最终得分 100
用户昵称 Gravatar打不死的羊 是否通过 通过
代码语言 Pascal 运行时间 0.177 s
提交时间 2009-11-11 15:15:03 内存使用 7.76 MiB
显示代码纯文本
program roads;
type
fxz1=array[1..1000] of real;
fxz2=array[1..1000,1..1000] of real;
fxz3=array[1..1000] of boolean;
var
f1,f2:text;
i,j,k,a,b,n,m:longint;
min,ans:real;
x,y,ls:fxz1;
map:fxz2;
f:fxz3;




begin assign(f1,'roads.in');
      assign(f2,'roads.out');
      reset(f1);rewrite(f2);
      readln(f1,n,m);
      for i:=1 to n do
      readln(f1,x[i],y[i]);
      for i:=1 to n do
      for j:=1 to n do
      map[i,j]:=sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j]));
      for i:=1 to m do
      begin readln(f1,a,b);
            map[a,b]:=0;
            map[b,a]:=0;
      end;
      for i:=1 to n do
      f[i]:=true;

      for i:=1 to n do
      ls[i]:=map[1,i];
      f[1]:=false;
      for i:=1 to n do
      begin
          min:=maxlongint;
          for j:=1 to n do
          if (f[j])and(ls[j]<min) then begin min:=ls[j];
                                                 k:=j;
                                            end;
          f[k]:=false;
          for j:=1 to n do
          if (map[k,j]<ls[j])and(f[j]) then ls[j]:=map[k,j];
      end;
      ans:=0;
      for i:=1 to n do
      ans:=ans+ls[i];
      writeln(f2,ans:0:2);
      close(f1);close(f2);
end.