Pagini recente » Cod sursa (job #521901) | Cod sursa (job #2930823) | Cod sursa (job #1670986) | Cod sursa (job #2808179) | Cod sursa (job #1456380)
#include <fstream>
#include <set>
#include <vector>
#include <cstring>
using namespace std;
ifstream fin ("zvon.in");
ofstream fout ("zvon.out");
const int Nmax = 100002;
int t, n;
vector<int> G[Nmax];
int Dfs(int x);
int main()
{
fin >> t;
while (t--)
{
for (int i = 1; i <= n; i++)
G[i].clear();
fin >> n;
for (int i = 1, x, y; i < n; i++)
{
fin >> x >> y;
G[x].push_back(y);
}
fout << Dfs(1) << '\n';
}
return 0;
}
int Dfs(int x)
{
multiset <int> q;
for ( auto y : G[x] )
{
q.insert(Dfs(y));
}
int z = 0, cnt = 1;
for (set < int > :: reverse_iterator it = q.rbegin(); it != q.rend(); it++)
{
z = max (z, *it + cnt);
cnt++;
}
return z;
}