比赛 20091111 评测结果 AAAAAAAAAA
题目名称 建造路径 最终得分 100
用户昵称 bly1991 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-11 10:55:47
显示代码纯文本
program bly(input,output);
var
  map:array[1..1000,1..1000] of real;
  low:array[1..1000] of real;
  p:array[1..1000] of boolean;
  x,y:array[1..1000] of real;
  ans,min:real;
  x0,y0,n,m,k:longint;
  i,j:longint;
  f1,f2:text;
begin
  assign(f1,'roads.in');
  reset(f1);
  readln(f1,n,m);
  for i:=1 to n do readln(f1,x[i],y[i]);
  for i:=1 to n do begin
    for j:=1 to n do begin
      map[i,j]:=sqrt((y[i]-y[j])*(y[i]-y[j])+(x[i]-x[j])*(x[i]-x[j]));
    end;
  end;
  for i:=1 to m do begin
    readln(f1,x0,y0);
    map[x0,y0]:=0;
    map[y0,x0]:=0;
  end;
  close(f1);

  for i:=1 to n do begin
    low[i]:=map[1,i];
    p[1]:=true;
  end;
  for i:=1 to n-1 do begin
    min:=maxlongint;
    for j:=1 to n do begin
      if (low[j]<min)and(p[j]=false) then begin
        min:=low[j];
        k:=j;
      end;
    end;
    p[k]:=true;
    for j:=1 to n do begin
      if (map[k,j]<low[j])and(p[j]<>true) then low[j]:=map[k,j];
    end;
  end;

  assign(f2,'roads.out');
  rewrite(f2);
  for i:=1 to n do ans:=ans+low[i];
  writeln(f2,ans:0:2);
  close(f2);
end.