Pagini recente » Cod sursa (job #152354) | Cod sursa (job #2467945) | Cod sursa (job #1919940)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
ifstream in("zvon.in");
ofstream out("zvon.out");
int t,n;
vector<int> L[100005];
int R[100005];
void read(){
int x,y;
in>>n;
for(int i=1;i<n;i++){
in>>x>>y;
L[x].push_back(y);
}
}
bool cmp(int a, int b){
return R[a]>R[b];
}
int dfs(int st){
int c=1;
for(auto x : L[st]){
dfs(x);
}
sort(L[st].begin(),L[st].end(),cmp);
for(auto x : L[st]){
R[st]=max(R[st],R[x]+c);
c++;
}
}
void solve_t(){
dfs(1);
out<<R[1]<<"\n";
memset(R,0,sizeof(R));
for(int i=1;i<=n;i++){
L[i].clear();
}
}
void solve(){
in>>t;
for(int o=1;o<=t;o++){
read();
solve_t();
}
}
int main(){
solve();
return 0;
}