Pagini recente » Monitorul de evaluare | Diferente pentru utilizator/iluv2k5 intre reviziile 3 si 2 | countblock | Diferente pentru utilizator/iluv2k5 intre reviziile 3 si 1 | Cod sursa (job #103669)
Cod sursa(job #103669)
type pnod=^nod;
nod=record
t:longint;
urm:pnod;
end;
var x,t,p,max,nrmax:array[1..100010]of longint;
v:array[1..100010]of pnod;
tt,n,i,j,k,a,b:longint;
aux:pnod;
procedure df(nod:longint);
var i,m,nr:longint;
begin
i:=1;
m:=0;nr:=0;
v[nod]:=v[nod]^.urm;
while v[nod]<> nil do
begin
df(v[nod]^.t);
/// writeln(v[nod]^.t);
if t[v[nod]^.t]=max[nod] then
inc(nrmax[nod]);
//inc(nr);
if t[v[nod]^.t]>max[nod] then
begin
max[nod]:=t[v[nod]^.t];
nrmax[nod]:=1;
{ m:=t[v[nod]^.t];
nr:=1;}
end;
v[nod]:=v[nod]^.urm;
end;
t[nod]:=max[nod]+nrmax[nod];
end;
begin
assign(input,'zvon.in');reset(input);
assign(output,'zvon.out');rewrite(output);
readln(tt);
for k:=1 to tt do
begin
readln(n);
fillchar(t,sizeof(t),0);
fillchar(nrmax,sizeof(nrmax),0);
fillchar(max,sizeof(max),0);
for i:=1 to n do
begin
new(v[i]);
v[i]^.urm:=nil;
end;
for i:=1 to n-1 do
begin
readln(a,b);
inc(x[a]);
aux:=new(pnod);
aux^.t:=b;
aux^.urm:=v[a]^.urm;
v[a]^.urm:=aux;
{ v[a]:=new(pnod);
v[a]^.t:=b;
v[a]^.urm:=nil;}
inc(p[a]);
end;
if n<>1 then
df(1);
writeln(t[1]);
//stergere lista
for i:=1 to n do
begin
while v[i]<>nil do
begin
aux:=v[i]^.urm;
v[i]^.urm:=aux^.urm;
dispose(aux);
end;
end;
end;
close(input);close(output);
end.