Cod sursa(job #99119)
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
const int maxN = 100001;
vector<int> fii[ maxN ];
int t;
int n;
int dfs( int nodc ) {
int i;
int x = fii[nodc].size();
for ( i = 0; i < fii[nodc].size(); i++ )
x = max( x, dfs( fii[nodc][i] )+1 );
return x;
}
int main()
{
int i,j;
int a,b;
freopen("zvon.in","r",stdin);
freopen("zvon.out","w",stdout);
scanf("%d\n", &t );
for (;t;t--) {
scanf("%d\n", &n );
for ( i = 1; i < maxN; i++ )
fii[i].clear();
for ( i = 1; i < n; i++ ) {
scanf("%d %d\n", &a, &b );
fii[ a ].push_back( b );
}
printf("%d\n", dfs( 1 ) );
}
fclose(stdin);
fclose(stdout);
return 0;
}