记录编号 23764 评测结果 AAAAAAAAAA
题目名称 公路修建 最终得分 100
用户昵称 Gravatarybh 是否通过 通过
代码语言 Pascal 运行时间 1.960 s
提交时间 2011-03-19 11:43:36 内存使用 0.19 MiB
显示代码纯文本
{公路修建
 最小生成树 prim
 Author: yangbohua
 Time: 2011-03-19}

program roadz;
const
  oo=10000000000000;
var
  x,y:array[1..5000] of longint;
  low:array[1..5000] of real;
  n,i,j,k,k1:longint;
  sum,min,temp,temp1,temp2:real;

begin
  assign(input,'roadz.in');
  reset(input);
  assign(output,'roadz.out');
  rewrite(output);

  readln(n);
  for i:=1 to n do
    readln(x[i],y[i]);

  sum:=oo;
  for i:=2 to n do
  begin
    temp1:=x[1]-x[i];
    temp2:=y[1]-y[i];
    low[i]:=sqr(temp1)+sqr(temp2);
    if low[i]<sum then
    begin
      sum:=low[i];
      k:=i;
    end;
  end;
  sum:=sqrt(sum);
  low[1]:=-1;
  for i:=1 to n-2 do
  begin
    min:=oo;
    low[k]:=-1;
    for j:=2 to n do
      if low[j]>-1 then
      begin
        temp1:=x[k]-x[j];
        temp2:=y[k]-y[j];
        temp:=sqr(temp1)+sqr(temp2);
        if temp<low[j] then low[j]:=temp;
        if low[j]<min then
        begin
          min:=low[j];
          k1:=j;
        end;
      end;
    sum:=sum+sqrt(min);
    k:=k1;
  end;

  writeln(sum:0:2);
  close(input);
  close(output);
end.