Pagini recente » Cod sursa (job #3139354) | Cod sursa (job #1231130) | Cod sursa (job #2782) | Cod sursa (job #317753) | Cod sursa (job #2958954)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("zvon.in");
ofstream fout("zvon.out");
int n;
vector <int> a[100005];
int t[100005];
bool cmp(int x, int y)
{
return t[x] > t[y];
}
void Dfs(int x)
{
for (auto w : a[x])
Dfs(w);
sort(a[x].begin(), a[x].end(), cmp);
int k = 1;
for (auto w : a[x])
{
t[x] = max(t[x], t[w] + k);
k++;
}
}
void Test_Case()
{
int i, x, y;
fin >> n;
for (i = 1; i < n; i++)
{
fin >> x >> y;
a[x].push_back(y);
}
Dfs(1);
fout << t[1] << "\n";
for (i = 1; i <= n; i++)
{
a[i].clear();
t[i] = 0;
}
}
int main()
{
int t;
fin >> t;
while (t--)
Test_Case();
return 0;
}