记录编号 49447 评测结果 TEEEE
题目名称 小树 最终得分 0
用户昵称 Gravatarluschegde 是否通过 未通过
代码语言 Pascal 运行时间 1.009 s
提交时间 2012-11-08 08:18:05 内存使用 0.19 MiB
显示代码纯文本
var
q:array [0..3000]of longint;
d:array [0..2000]of longint;
c:array [0..50,0..50]of longint;
z:array [0..50]of longint;
vi:array [0..50]of boolean;
n,i,t,j,len,xt,a,b,e:longint;  max:real;
  procedure bfs(v:longint);
  var t,h,k:longint;
   begin
    fillchar(vi,sizeof(vi),false);
        h:=0;
	t:=1;
	q[1]:=v;
	vi[v]:=true;
	len:=1;
	while h<=t do
	begin
	inc(h);
	k:=q[h];
	for i:=0 to n do
	 if (c[k,i]<>-1) and (not vi[i]) then
	 begin
	  z[i]:=z[k]+c[k,i];
	  if (max=0) or (max<z[i]/len) then
	  max:=z[i]/len;
	  inc(len);
	  vi[i]:=true;
	  inc(t);
	  q[t]:=i;
         end;
        end;
   end;
   procedure main;
   begin
   assign(input,'treec.in');
   reset(input);
   assign(output,'treec.out');
   rewrite(output);
    readln(xt);
	for i:=1 to xt do
        begin
	 readln(n);
	 for j:=1 to n-1 do
	 begin
	 readln(a,b,e);
	 c[a,b]:=e;
         end;
	bfs(0);
	writeln(max:0:3);
        end;
        close(input);
        close(output);
   end;
   begin
    main;
   end.