记录编号 49178 评测结果 AAAAA
题目名称 小树 最终得分 100
用户昵称 GravatarSweet 是否通过 通过
代码语言 Pascal 运行时间 0.007 s
提交时间 2012-11-07 14:25:52 内存使用 0.21 MiB
显示代码纯文本
type point=^node;
		node=record
		data,w:longint;
		next:point;
		end;


var t,k,i,j,fa,n,x,y,z:longint;
		ans:double;
		son:array[0..1010] of point;
		f1,f2:array[0..1010] of longint;
                b:array[1..10000] of longint;
                p:point;

function max(x,y:double):double;
begin
if x>y then exit(x) else exit(y);
end;

begin
assign(input,'treec.in');
assign(output,'treec.out');
reset(input);
rewrite(output);

readln(t);

for k:=1 to t do
	begin

	readln(n);

	for i:=0 to n-1 do
		begin
		son[i]:=nil;
		f1[i]:=0;
		f2[i]:=0;
		end;

	for i:=1 to n-1 do
		begin
		readln(x,y,z);
		new(p);
		p^.data:=y;
		p^.w:=z;
		p^.next:=son[x];
		son[x]:=p;
		end;

	i:=1;
	j:=2;
	ans:=0;
	b[1]:=0;
	while i<>j do
		begin
		fa:=b[i];
		p:=son[fa];
		while p<>nil do
			begin
			f1[p^.data]:=f1[fa]+p^.w;
			f2[p^.data]:=f2[fa]+1;
			ans:=max(ans,f1[p^.data]/f2[p^.data]);
			b[j]:=p^.data;
			inc(j);
			p:=p^.next;
			end;
		inc(i);
		end;
	
	writeln(ans:0:2);
	
	end;

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