记录编号 49208 评测结果 AAAAA
题目名称 小树 最终得分 100
用户昵称 Gravatarbw 是否通过 通过
代码语言 Pascal 运行时间 0.007 s
提交时间 2012-11-07 15:00:56 内存使用 0.19 MiB
显示代码纯文本
program ex;
  type pt=^dy;
    dy=record
    link,data,fa:longint;
    next:pt;
    end;
    var a:array[0..1000] of dy;
    q:array[1..1000,1..3] of longint;
    ans:real;
    p:pt;
     i,j,k,shou,n,t,x,y,z,head,tail:longint;
     function max(x,y:real):real;
      begin
       if x>y then exit(x); exit(y);
      end;
     function get(x:longint):longint;
      begin
       if a[x].fa=x then exit(x);
       exit(get(a[x].fa));
      end;
     procedure lian(x,y,z:longint);
      begin
       new(p);
       p^.link:=y;
       p^.data:=z;
       p^.next:=a[x].next;
       a[y].fa:=x;
       a[x].next:=p;
      end;
     procedure sou;
      begin
       while head<=tail do
        begin
         p:=a[q[head,1]].next;
         while p<>nil do
          begin
           inc(tail);
           q[tail,1]:=p^.link;
           q[tail,2]:=q[head,2]+1;
           q[tail,3]:=q[head,3]+p^.data;
           p:=p^.next;
          end;
          inc(head);
        end;
      end;
      begin
      assign(input,'treec.in');
      assign(output,'treec.out');
      reset(input);
      rewrite(output);
       read(t);
        for i:=1 to t do
         begin
         ans:=-maxlongint;;
         read(n);
         if n=1then begin writeln('0.00'); continue; end;
         for j:=0 to n-1 do
         begin
          a[j].fa:=j;
          a[j].next:=nil;
         end;
          for j:=1 to n-1 do
           begin
           read(x,y,z);
           lian(x,y,z);
           end;
          shou:=get(1);
         fillchar(q,sizeof(q),0);
         q[1,1]:=shou;
         q[1,2]:=0;
         head:=1; tail:=1;
         sou;
         for j:=2 to tail do
            ans:=max(ans,q[j,3]/q[j,2]);
           writeln(ans:0:2);
        end;
        close(input); close(output);
       end.