Pagini recente » Cod sursa (job #3226489) | Cod sursa (job #1575042) | Cod sursa (job #871333) | Cod sursa (job #3189214) | Cod sursa (job #1525643)
#include <bits/stdc++.h>
using namespace std;
int n,T,sol;
vector<int> L[100003];
ifstream fin("zvon.in");
ofstream fout("zvon.out");
inline void Citire()
{
int i,x,y;
fin>>n;
for(i=1;i<n;++i)
{
fin>>x>>y;
L[min(x,y)].push_back(max(x,y));///minim???
}
}
inline void DFS(int x,int c)
{
int w;
unsigned int k;
sol=max(sol,c);
for(k=0;k<L[x].size();++k)
{
w=L[x][k];
DFS(w,c+k+1);
}
}
inline bool cmp(int A, int B)
{
return (L[A].size()>L[B].size());
}
inline void Solutie()
{
int i;
for(i=1;i<=n;++i)
sort(L[i].begin(),L[i].end(),cmp);
DFS(1,0);
fout<<sol<<"\n";
}
inline void Reinit()
{
int i;
for(i=1;i<=n;++i)
L[i].clear();
sol=0;
}
int main()
{
int i,j,k;
fin>>T;
for(i=1;i<=T;++i)
{
//cout<<"Testul "<<i<<":\n";
Citire();
Solutie();
/*for(k=1;k<=n;++k)
{
cout<<k<<": ";
for(j=0;j<L[k].size();++j)
cout<<L[k][j]<<" ";
cout<<"\n";
}
cout<<"\n\n";*/
Reinit();
}
return 0;
}