比赛 20121107 评测结果 EEEE
题目名称 小树 最终得分 10
用户昵称 极寒之魇 运行时间 0.060 s
代码语言 Pascal 内存使用 4.11 MiB
提交时间 2012-11-07 11:24:23
显示代码纯文本
uses math;
type point=^node;
     node=record
      ve:longint;
      next:point;
      data:longint;
     end;
var a:array[0..200] of node;
    f:array[1..1000000] of longint;
    v:array[0..200] of boolean;
    dis:array[0..200]of longint;
    mo:array[0..200] of longint;
    i,n,t,j:longint;
    ans:real;

procedure init;
  var x,y,z,i:longint;
      p:point;
  begin
   for i:=1 to n do
   begin new(p); a[i].ve:=0; a[i].next:=nil; a[i].data:=0; end;
   for i:=1 to n-1 do
   begin readln(x,y,z);
         new(p); a[x].ve:=x; p^.ve:=y; p^.next:=a[x].next; a[x].next:=p; p^.data:=z;
   end;
   end;

procedure spfa;
  var head,tail,now:longint;
      p:point;
  begin
  fillchar(v,sizeof(v),false);
  fillchar(dis,sizeof(dis),$7f);
  fillchar(mo,sizeof(mo),0);
  fillchar(f,sizeof(f),0);
  head:=0; tail:=1; f[1]:=a[0].ve;
  v[f[1]]:=true; dis[0]:=0;
  while head<>tail do
  begin
  inc(head); head:=head mod 1000000; now:=f[head];
  p:=a[now].next;
  while p<>nil do
  begin
  if dis[p^.ve]>dis[now]+p^.data then begin
     dis[p^.ve]:=dis[now]+p^.data;
     mo[p^.ve]:=mo[now]+1;
     if not v[p^.ve] then begin inc(tail); tail:=tail mod 1000000;
                                  f[tail]:=p^.ve; v[f[tail]]:=true; end;
     end;
     p:=p^.next;
     end;
     v[f[head]]:=false;
     end;
     end;

begin
  assign(input,'treec.in'); reset(input);
  assign(output,'treec.out'); rewrite(output);
  readln(t);
  for i:=1 to t do
  begin
  ans:=0;
  readln(n);
  if n=1 then begin writeln(ans:0:2); continue; end;
  init;
  spfa;
  for j:=1 to n-1 do
  ans:=max(ans,dis[j]/mo[j]);
  writeln(ans:0:2);
  end;
  close(output);
end.