记录编号 15251 评测结果 AEAAAAAEEE
题目名称 [USACO Dec07] 建造路径 最终得分 60
用户昵称 Gravatarmaxiem 是否通过 未通过
代码语言 Pascal 运行时间 0.104 s
提交时间 2009-11-11 12:13:54 内存使用 9.67 MiB
显示代码纯文本
program roads;
var
  p:array [1..1000] of record
    x,y:longint;
  end;
  table:array [1..1000,1..1000] of extended;
  low:array [1..1000] of extended;
  flag:array [1..1000] of boolean;
  a,b,i,j,k,n,m:longint;
  tmp:int64;
  min,sum:extended;
begin
  assign (input,'roads.in');
  reset (input);
  readln (n,m);
  for i:=1 to n do for j:=1 to n do table[i,j]:=1000000000.0;
  for i:=1 to n do readln (p[i].x,p[i].y);
  for i:=1 to n-1 do for j:=i+1 to n do begin
    tmp:=sqr(p[i].x-p[j].x)+sqr(p[i].y-p[j].y);
    table[i,j]:=sqrt(tmp);
    table[j,i]:=table[i,j];
  end;
  for i:=1 to m do begin
    readln (a,b);
    table[a,b]:=0;
    table[b,a]:=0;
  end;
  for i:=1 to n do low[i]:=table[1,i];
  k:=1;flag[1]:=true;
  for i:=1 to n-1 do begin
    min:=maxlongint;
    for j:=1 to n do if (low[j]<min) and (flag[j]=false) then begin
      min:=low[j];
      k:=j;
    end;
    sum:=sum+min;
    flag[k]:=true;
    for j:=1 to n do if table[k,j]<low[j] then low[j]:=table[k,j];
  end;
  fillchar (flag,sizeof(flag),0);
  close (input);
  assign (output,'roads.out');
  rewrite (output);
  writeln (sum:0:2);
  close (output);
end.