比赛 HAOI2009 模拟试题1 评测结果 WWWEEEEEEE
题目名称 洞窟探索 最终得分 0
用户昵称 .Xmz 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-04-21 11:25:56
显示代码纯文本
program xmz;
var
dep,n,m,a,b,aa,bb,l,zh,ss,max:longint;
x:array[1..150,1..150]of longint;
y:array[1..150,0..3]of longint;
z:array[1..100]of longint;
bl:array[1..150]of boolean;
f1,f2:text;
procedure dps(xx:integer);
var i:integer;
 begin
 if dep<m then
 begin
 dep:=dep+1;
  if dep<>m then for i:=1 to 3 do
  if (y[xx,i]<>0)and(bl[y[xx,i]]=false) then
  begin
   zh:=zh+1;z[zh]:=y[xx,i];bl[z[zh]]:=true;dps(z[zh]);
  end;
 end;
 if dep=m then
 begin
       for a:=1 to zh do
        for b:=a+1 to zh do
         ss:=x[z[a],z[b]]+ss;
       if ss<max then max:=ss;
       ss:=0;
      end;
 bl[z[zh]]:=false;zh:=zh-1;dep:=dep-1;
 end;

procedure floyd;
var k,i,j:integer;
 begin
  for k:=1 to n do
   for i:=1 to n do
    for j:=1 to n do
     if (x[i,k]+x[k,j]<x[i,j])and(i<>j)and(j<>k)and(i<>k) then
      begin
       x[i,j]:=x[i,k]+x[k,j];

      end;
 end;

begin
 assign(f1,'hole.in');reset(f1);
 assign(f2,'hole.out');rewrite(f2);
   read(f1,n,m);
 for a:=1 to n do for b:=1 to n do x[a,b]:=9999999;
 for a:=1 to n-1 do
  begin
   read(f1,aa,bb,l);
   x[aa,bb]:=l;
   x[bb,aa]:=l;
   y[aa,0]:=y[aa,0]+1;y[aa,y[aa,0]]:=bb;
   y[bb,0]:=y[bb,0]+1;y[bb,y[bb,0]]:=aa;
  end;
 floyd;
 max:=9999999;
 zh:=zh+1;z[zh]:=1;bl[1]:=true;dps(1);
write(f2,(max/(m*(m-1)/2)):0:2);
close(f1);close(f2);
end.