Pagini recente » Cod sursa (job #589806) | Cod sursa (job #70387) | Cod sursa (job #2809650) | Cod sursa (job #1912713) | Cod sursa (job #101388)
Cod sursa(job #101388)
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
#define pb push_back
#define NMAX 100010
#define MP make_pair
#define sz size()
#define ss second
#define ff first
int n;
vector<int> list[NMAX];
int niv[NMAX], nr[NMAX];
int _max = 0;
inline int MAX(int a, int b) { return (a > b) ? (a) : (b); }
void read()
{
scanf("%d", &n);
for(int i = 1, x, y; i < n; ++i)
{
scanf("%d %d\n", &x, &y);
list[x].pb(y);
}
}
int df(int x)
{
if(!(list[x].sz))
return 0;
vector<int> p;
for(vector<int> :: iterator it = list[x].begin(); it != list[x].end(); ++it)
p.pb(df(*it));
sort(p.begin(), p.end());
int _max = 0;
for(int t = 1, it = p.sz-1; it >= 0; --it, ++t)
_max = MAX(_max, p[it] + t);
return _max;
}
int main()
{
freopen("zvon.in", "r", stdin);
freopen("zvon.out", "w", stdout);
int nr;
for(scanf("%d", &nr); nr; --nr)
{
read();
printf("%d\n", df(1));
memset(niv, 0, sizeof(niv));
for(int i = 0; i < NMAX; ++i)
list[i].clear();
_max = 0;
}
return 0;
}