Pagini recente » Cod sursa (job #2307392) | Cod sursa (job #1589113) | Cod sursa (job #1104209) | Cod sursa (job #1502655) | Cod sursa (job #329043)
Cod sursa(job #329043)
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 60000;
int n;
int d[N];
vector<int> v[N];
inline int max ( int a, int b ) { return (a > b) ? a : b; }
void df ( int x ) {
vector<int> t;
for (int i = 0; i < v[x].size(); ++i) {
df(v[x][i]);
t.push_back(d[v[x][i]]);
}
sort(t.begin(),t.end());
if (t.size()>0) {
d[x] = t[t.size()-1]+1;
for (int i = 0; i < t.size(); ++i) {
d[x] = max(d[x],t[i]+t.size()-i);
}
}
}
/*while (scanf(" %s", ss2)==1)
{
l = strlen(ss2);
val = 0;
pp = 1;
for (i = 0; i < l; i++) val = val+(ss2[i]-cst)*pp, pp *= 3;
hash = val&S;
t = 0;
while ((V[hash]>0)&&(Val[hash]!=val)) hash = (hash+(++t))&S;
V[hash] = 1; Val[hash] = val;
}
cst = 'a';
val = 0; pp = 1;
for (i = 0; i < l; i++) val = val+(ss[i]-cst)*pp, pp *= 3;
p = pp/3;
hash = val&S; Nr+=V[hash];
*/
int main()
{
freopen("zvon.in","rt",stdin);
freopen("zvon.out","wt",stdout);
int t;
for (scanf("%d",&t); t > 0; --t) {
scanf("%d",&n);
for (int i = 0; i<N; ++i) {
v[i].clear();
d[i] = 0;
}
for (int i = 0; i < n-1; ++i) {
int a,b;
scanf("%d %d",&a,&b);
--a; --b;
v[a].push_back(b);
}
df(0);
printf("%d\n",d[0]);
}
return 0;
}