记录编号 | 49117 | 评测结果 | AAAAA | ||
---|---|---|---|---|---|
题目名称 | 小树 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | Pascal | 运行时间 | 0.118 s | ||
提交时间 | 2012-11-07 12:57:09 | 内存使用 | 3.99 MiB | ||
program treec; var t,loop,x,y,w,i,ans,road,n,k:longint; l,max:real; a:array[0..1000,0..1000]of longint; f:array[0..1000]of longint; begin assign(input,'treec.in'); reset(input); assign(output,'treec.out'); rewrite(output); read(t); for loop:=1 to t do begin fillchar(f,sizeof(f),255); fillchar(a,sizeof(a),0); read(n); for i:=1 to n-1 do begin read(x,y,w); f[y]:=x; a[x,y]:=w; end; f[0]:=-2; max:=0; for i:=1 to n do begin k:=i; ans:=0; road:=0; l:=0; while f[k]<>-2 do begin inc(ans); inc(road,a[f[k],k]); k:=f[k]; if k=-1 then begin ans:=0; road:=0; end; end; if ans<>0 then l:=road/ans; if l>max then max:=l; end; writeln(max:0:2); end; close(input); close(output); end.