比赛 20121107 评测结果 TWW
题目名称 小树 最终得分 6
用户昵称 luschegde 运行时间 1.005 s
代码语言 Pascal 内存使用 3.99 MiB
提交时间 2012-11-07 11:52:51
显示代码纯文本
var
cost:array [0..1000,0..1000]of longint;
ans:longint; max:real;
t,n,i:longint;
vis:array [0..1000]of boolean;

 procedure search(s,ci:longint);
  begin
    //if ci>n then exit;
    for i:=0 to n-1 do
     if (cost[s,i]<>-1) and (not vis[i]) then
     begin
        ans:=ans+cost[s,i];
        vis[i]:=true;
    if ans/ci>max then max:=ans/ci;
        search(i,ci+1);
        ans:=ans-cost[s,i];
        vis[i]:=false;
     end;
  end;
    procedure main;
  var a,b,e,t,j,j1:longint;
  begin
  assign(input,'treec.in');
    assign(output,'treec.out');
    reset(input);
    rewrite(output);
    readln(t);
    for i:=1 to t do
    begin
     readln(n);
     max:=0;
     for j1:=0 to n-1 do
      for j:=0 to n-1 do
       cost[j1,j]:=-1;
      fillchar(vis,sizeof(vis),false);
     for j:=1 to n-1 do
     begin
     readln(a,b,e);
     cost[a,b]:=e;
     end;
      vis[0]:=true;
     search(0,1);
     writeln(max:0:2);
    end;
  end;

begin
   main;
  close(input);
   close(output)
end.