比赛 |
20121107 |
评测结果 |
AAAAA |
题目名称 |
小树 |
最终得分 |
100 |
用户昵称 |
RoyJames |
运行时间 |
0.007 s |
代码语言 |
Pascal |
内存使用 |
0.19 MiB |
提交时间 |
2012-11-07 11:49:48 |
显示代码纯文本
program treec;
var
t,n,i,a,b,c,tot:longint;
next,e,w,head,dis,wei:array[0..1000]of longint;
procedure insert(u,v,len:longint);
begin
inc(tot);
next[tot]:=head[u];
head[u]:=tot;
w[tot]:=len;
e[tot]:=v;
end;
procedure make(cur,len,cost:longint);
var j:longint;
begin
j:=head[cur];
wei[cur]:=cost;
dis[cur]:=len;
while j<>-1 do
begin
make(e[j],len+1,cost+w[j]);
j:=next[j];
end;
end;
function max(a,b:double):double;
begin
if a>b then exit(a)else exit(b);
end;
function dp(cur:longint):double;
var j:longint; temp:double;
begin
j:=head[cur];
if cur<>0 then dp:=wei[cur]/dis[cur]else dp:=0;
while j<>-1 do
begin
dp:=max(dp,dp(e[j]));
j:=next[j];
end;
end;
begin
assign(input,'treec.in');
assign(output,'treec.out');
reset(input);
rewrite(output);
readln(t);
while t>0 do
begin
readln(n);
for i:=0 to n-1 do head[i]:=-1;
tot:=0;
for i:=1 to n-1 do
begin
readln(a,b,c);
insert(a,b,c);
end;
make(0,0,0);
writeln(dp(0):0:2);
dec(t);
end;
close(input);
close(output);
end.