比赛 20091111 评测结果 AEWWWWWEEE
题目名称 建造路径 最终得分 10
用户昵称 王瑞祥K 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-11 09:08:50
显示代码纯文本
program roads(input,output);
var
 map:array[1..1000,1..1000]of double;
 farm:array[1..1000,1..2]of longint;
 lowcost:array[1..1000]of double;
 i,j,k,n,m,x,y:longint;
 min,ans:double;
begin
 assign(input,'roads.in');assign(output,'roads.out');
 reset(input);rewrite(output);
 readln(n,m);
 for i:=1 to n do readln(farm[i,1],farm[i,2]);
 for i:=1 to n do
  for j:=1 to n do
   map[i,j]:=sqrt(sqr(farm[i,1]-farm[j,1])+sqr(farm[i,2]-farm[j,2]));
 for i:=1 to n do lowcost[i]:=map[1,i];
 for i:=1 to m do begin
  read(x,y);
  lowcost[y]:=0;
  for j:=1 to n do if map[y,j]<lowcost[j] then lowcost[j]:=map[y,j];
 end;
 ans:=0;
 for i:=1 to n-m-1 do begin
  min:=10e20;
  for j:=1 to n do
   if (lowcost[j]<min)and(lowcost[j]<>0) then begin
    min:=lowcost[j];
    k:=j;
   end;
  ans:=ans+lowcost[k];
  lowcost[k]:=0;
  for j:=1 to n do
   if map[k,j]<lowcost[j] then lowcost[j]:=map[k,j];
 end;
 writeln(ans:0:2);
 close(input);close(output);
end.