比赛 |
20121107 |
评测结果 |
AAAAA |
题目名称 |
小树 |
最终得分 |
100 |
用户昵称 |
稠翼 |
运行时间 |
0.008 s |
代码语言 |
Pascal |
内存使用 |
0.18 MiB |
提交时间 |
2014-09-20 20:49:35 |
显示代码纯文本
program cogs1256;
type nod=record
n,d,y:longint;
end;
var
a:array[0..1100]of longint;
b:array[0..1100]of nod;
n,i,ii,t,x,tt,k:longint;
max:double;
procedure dfs(t,s:longint;d:int64);
forward;
procedure init;
begin
assign(input,'treec.in');reset(input);
assign(output,'treec.out');rewrite(output);
end;
procedure main;
begin
readln(tt);
for ii:=1 to tt do
begin
fillchar(a,sizeof(a),0);
readln(n);
for i:=1 to n-1 do
begin
read(x,b[i].y,b[i].d);
b[i].n:=a[x];a[x]:=i;
end;
if n=1 then max:=0 else max:=-maxlongint;
dfs(0,0,0);
writeln(max:0:2);
end;
end;
procedure dfs(t,s:longint;d:int64);
var
p:longint;
begin
if t>0 then if d/s>max then max:=d/s;
p:=a[t];
while p<>0 do
begin
dfs(b[p].y,s+1,d+b[p].d);
p:=b[p].n;
end;
end;
begin
init;
main;
close(output);
end.//complete by chouyi20140920