比赛 20091111 评测结果 AEWWWWWEEE
题目名称 建造路径 最终得分 10
用户昵称 Hamster 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-11 10:32:55
显示代码纯文本
program roads;
var
  map:array[0..1001,0..1001]of double;
  f:array[0..1001]of boolean;
  v:array[0..1001]of double;
  a:array[0..1001,1..2]of integer;
  n,m,i,j,k,l:longint;
  min:double;
begin
  assign(input,'roads.in');
  assign(output,'roads.out');
  reset(input); rewrite(output);
  readln(n,m);
  
  fillchar(v,sizeof(v),0);
  fillchar(f,sizeof(f),0);
  fillchar(a,sizeof(a),0);
  for i:=1 to n+1 do 
  begin
    for j:=1 to n+1 do map[i,j]:=999999999;
  end;
  for i:=1 to n do readln(a[i,1],a[i,2]);
  for i:=1 to m do 
  begin
    readln(j,k);
    map[j,k]:=0; map[k,j]:=0;
  end;
  
  for i:=1 to n do 
  begin
    for j:=1 to n do 
	begin
      if (map[i,j]<>0) and (i<>j) then map[i,j]:=sqrt((a[i,1]-a[j,1])*(a[i,1]-a[j,1])+(a[i,2]-a[j,2])*(a[i,2]-a[j,2]));
    end;
  end;
  v[1]:=0;
  for i:=2 to n do v[i]:=map[1,i];
  f[1]:=false;
  for i:=1 to n-1 do 
  begin
    min:=999999999;
    for j:=1 to n do 
	begin
      if (f[j])and(v[j]<min) then 
	  begin
        min:=v[j];
        k:=j;
      end;
    end;
    f[k]:=false;
    for j:=1 to n do if (map[k,j]<v[j]) then v[j]:=map[k,j];
  end;
  min:=0;
  for i:=1 to n do min:=min+v[i];
  writeln(min:0:2);
  
  close(input);
  close(output);
end.