记录编号 15363 评测结果 AAAAAAAAAA
题目名称 [USACO Dec07] 建造路径 最终得分 100
用户昵称 GravatarReimBurSe. 是否通过 通过
代码语言 Pascal 运行时间 0.991 s
提交时间 2009-11-12 16:09:44 内存使用 9.67 MiB
显示代码纯文本
Program roads;

Type
abc=record
 x,y:int64;
end;
sc=array [1..1000] of abc;
sc1=array [1..1000,1..1000] of extended;
sc2=array [1..1000] of boolean;
sc3=array [1..1000] of extended;

Var
z:sc;
s:sc1;
i,j,p:longint;
n,m,nn:int64;
xx,yy,pp,qq:int64;
temp,min,l:extended;
panduan:sc2;
o:boolean;
a:sc3;

Begin
assign(input,'roads.in');
assign(output,'roads.out');
reset(input);
rewrite(output);
readln(n,m);
for i:=1 to n do
 for j:=1 to n do
  s[i,j]:=9999999999999999;
for i:=1 to n do panduan[i]:=false;
for i:=1 to n do readln(z[i].x,z[i].y);
for i:=1 to m do begin
 readln(xx,yy);
 s[xx,yy]:=-1;
 s[yy,xx]:=-1;
end;
nn:=n-1-m;
for i:=1 to n do begin
 for j:=1 to n do begin
  if (i<>j)and(s[i,j]<>-1) then begin
   xx:=z[i].x;
   yy:=z[i].y;
   pp:=z[j].x;
   qq:=z[j].y;
   temp:=0;
   if xx>=pp then temp:=temp+(xx-pp)*(xx-pp)
   else temp:=temp+(pp-xx)*(pp-xx);
   if yy>=qq then temp:=temp+(yy-qq)*(yy-qq)
   else temp:=temp+(qq-yy)*(qq-yy);
   s[i,j]:=sqrt(temp);
  end;
  if s[i,j]=-1 then s[i,j]:=0;
 end;
end;
l:=0;
o:=false;
panduan[1]:=true;
for i:=1 to n do a[i]:=s[1,i];
while o=false do begin
 min:=999999999999999999;
 for i:=1 to n do begin
  if (a[i]<min)and(panduan[i]=false) then begin
   min:=a[i];
   xx:=i;
  end;
 end;
 l:=l+min;
 panduan[xx]:=true;
 p:=1;
 while panduan[p]=true do p:=p+1;
 if p=n+1 then o:=true;
 for j:=1 to n do
  if s[xx,j]<a[j] then a[j]:=s[xx,j];
end;
writeln(l:0:2);
close(input);
close(output);
End.