Pagini recente » Statistici pruna cosmin (prunacosmin1) | Cod sursa (job #391490) | Cod sursa (job #282395) | Cod sursa (job #1961076) | Cod sursa (job #105583)
Cod sursa(job #105583)
#include<cstdio>
#include<algorithm>
struct celula{
long inf;
celula *leg;
}*a[101000],*p;
long i,test,k,n,x,y;
bool desc(long a,long b){
if(a>b)return 1;
else return 0;
}
long df(long x){
long t[100000],m=0,q;
p=a[x];
while(p!=0){
t[q++]=df(p->inf);
p=p->leg;
}
std::sort(t,t+q,desc);
for(k=0;k<q;k++)
if(t[k]+k>m)m=t[k]+k;
return m;
}
int main(){
freopen("zvon.in","r",stdin);
freopen("zvon.out","w",stdout);
scanf("%ld",&test);
for(i=0;i<test;i++){
scanf("%ld",&n);
for(k=0;k<n;k++)
a[k]=0;
for(k=0;k<n-1;k++){
scanf("%ld%ld",&x,&y);
p=new celula;
p->inf=y;p->leg=a[x];a[x]=p;
}
printf("%ld\n",df(1));
}
fclose(stdin);
fclose(stdout);
return 0;
}