Pagini recente » Cod sursa (job #1002183) | Cod sursa (job #1450137) | Cod sursa (job #1904298) | Cod sursa (job #989408) | Cod sursa (job #2637907)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 100005;
ifstream fin("zvon.in");
ofstream fout("zvon.out");
vector<int> g[N];
int dp[N], Subordonati[N];
int TimpMax;
int df(int nod)
{
vector<int> timp;
for(int y : g[nod])
timp.push_back(df(y));
sort(timp.begin(), timp.end());
reverse(timp.begin(), timp.end());
int mx = 0;
for(int i = 0; i < timp.size(); i++)
mx = max(mx, i + 1 + timp[i]);
return mx;
}
void sterge(int n)
{
for(int i = 1; i <= n; i++)
{
g[i].clear();
Subordonati[i] = 0;
dp[i] = 0;
}
}
int main()
{
int t;
fin >> t;
while (t--)
{
int n;
fin >> n;
for(int i = 1; i < n; i++)
{
int x, y;
fin >> x >> y;
g[x].push_back(y);
}
fout << df(1) << '\n';
sterge(n);
}
return 0;
}