Pagini recente » Cod sursa (job #1875) | Cod sursa (job #2798974) | Cod sursa (job #747725) | Cod sursa (job #2810612) | Cod sursa (job #2816884)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("zvon.in");
ofstream fout("zvon.out");
const int M=100005;
int t,n,tmax,a,b,viz[M];
vector < int > v[M];
void DFS(int nod, int timp)
{
if(timp>tmax)
tmax=timp;
viz[nod]=1;
for(auto vec : v[nod])
if(!viz[vec])
DFS(vec,timp+1);
}
int main()
{
fin >> t;
for(;t;--t)
{
fin >> n;
tmax=0;
for(int i=0;i<M;i++)
{
v[i].clear();
viz[i]=0;
}
for(int i=1;i<n;i++)
{
fin >> a >> b;
v[a].push_back(b);
}
DFS(1,1);
fout << (n==1?0:tmax) << '\n';
}
return 0;
}