比赛 20091111 评测结果 AEWWWWWEEE
题目名称 建造路径 最终得分 10
用户昵称 ZhouZn1 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-11 09:35:13
显示代码纯文本
program roads;
var
        a:array[1..1000,1..1000]of double;
        data:array[1..2,1..1000]of longint;
        m,n,i,j,x,y:longint;
        mincost:array[1..1001]of double;
        closed:array[1..1001]of longint;
function dist(x1,y1,x2,y2:longint):double;
begin
        exit(sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
end;
procedure init;
var
        dd:double;
begin
        assign(input,'roads.in');
        reset(input);
        assign(output,'roads.out');
        rewrite(output);
        readln(n,m);
        for i:=1 to n do
         for j:=1 to n do a[i,j]:=-1;
        for i:=1 to n do
        readln(data[1,i],data[2,i]);
        for i:=1 to n-1 do
         for j:=i+1 to n do
          begin
          dd:=dist(data[1,i],data[2,i],data[1,j],data[2,j]);
          a[i,j]:=dd;
          a[j,i]:=dd;
          end;
        for i:=1 to  m do
        begin
                readln(x,y);
                a[x,y]:=0;
                a[y,x]:=0;
        end;
        for i:=1 to n do
        begin
        mincost[i]:=a[1,i];
        closed[i]:=1;
        end;
end;
procedure closef;
begin
        close(input);
        close(output);
end;
procedure main;
var
        i,j,p:longint;
        min,ans:double;
begin
        mincost[1]:=-1;
        for i:=1 to n-1 do
        begin
          p:=0;
          min:=maxlongint;
          for j:=1 to n do
           if (mincost[j]<>-1)and(mincost[j]<min) then
           begin
                min:=mincost[j];
                p:=j;
           end;
           if p=0 then break;
           mincost[p]:=-1;
          for j:=1 to n do
           if (a[p,j]<>-1)and((mincost[j]=-1)or(a[p,j]<mincost[j]))then
           begin
                mincost[j]:=a[p,j];
                closed[j]:=p;
           end;
        end;
        ans:=0;
        for i:=1 to n do
        ans:=ans+a[i,closed[i]];
        writeln(ans:0:2);
end;
begin
        init;
        main;
        closef;
end.