记录编号 15464 评测结果 AAAAAAAAAA
题目名称 [USACO Dec07] 建造路径 最终得分 100
用户昵称 Gravatarreamb 是否通过 通过
代码语言 Pascal 运行时间 0.464 s
提交时间 2009-11-13 10:27:57 内存使用 7.76 MiB
显示代码纯文本
program jianzaolujing;
var
  jilu:array[1..1000,1..1000] of real;
  juli:array[1..1000] of real;
  t,min:real;
  n,m,i,j,k:integer;
  x1,y1:int64;
  biaozhi:array[1..1000] of boolean;
  zuobiao:array[1..1000,1..2]of int64;
begin
  assign (input,'roads.in');
  reset (input);
  assign (output,'roads.out');
  rewrite (output);
  readln (n,m);
  for i:=1 to n do
  begin
    readln (x1,y1);
    zuobiao[i,1]:=x1;
    zuobiao[i,2]:=y1;
    for j:=1 to i-1 do
    begin
      jilu[j,i]:=sqrt(sqr(x1-zuobiao[j,1])+sqr(y1-zuobiao[j,2]));
      jilu[i,j]:=jilu[j,i]
    end
  end;
  for i:=1 to m do
  begin
    readln (x1,y1);
    jilu[x1,y1]:=0;
    jilu[y1,x1]:=0
  end;
  for i:=2 to n do
    juli[i]:=jilu[1,i];
  for i:=1 to n do
    biaozhi[i]:=true;
  biaozhi[1]:=false;
  for i:=1 to n-1 do
  begin
    min:=maxlongint;
    for j:=1 to n do
      if (juli[j]<min) and (biaozhi[j]=true) then
      begin
        min:=juli[j];
        k:=j
      end;
      t:=t+juli[k];
      biaozhi[k]:=false;
      for j:=1 to n do
        if jilu[k,j]<juli[j] then
          juli[j]:=jilu[k,j]
  end;
  writeln (t:0:2);
  close (input);
  close (output)
end.