Pagini recente » Cod sursa (job #366576) | Cod sursa (job #2058368) | Cod sursa (job #2736637) | Cod sursa (job #2141290) | Cod sursa (job #2777804)
#include <fstream>
#include <vector>
#include <algorithm>
std::ifstream in("zvon.in");
std::ofstream out("zvon.out");
const int N = 1e5+1;
std::vector<int> g[N];
int dfs(int i){
if(g[i].empty()){
return 0;
}
int nodeNmb = g[i].size();
int time[nodeNmb],cnt=-1;
for(auto node : g[i]){
time[++cnt] = dfs(node);
//out<<time[cnt]<<'\n';
}
std::sort(time,time+nodeNmb,std::greater<int>());
int maxT = -N;
for(int j=0;j<nodeNmb;++j){
time[j] += j+1;
maxT = std::max(maxT,time[j]);
}
return maxT;
}
int main()
{
int t;
in>>t;
for(int i=0;i<t;++i){
int n;
in>>n;
for(int j=1;j<=n;++j){
g[j].clear();
}
for(int j=1;j<n;++j){
int a,b;
in>>a>>b;
g[a].push_back(b);
}
out<<dfs(1)<<'\n';
}
return 0;
}