Pagini recente » Cod sursa (job #1617052) | Cod sursa (job #1995247) | Cod sursa (job #1993617) | Cod sursa (job #1644980) | Cod sursa (job #1512244)
#include <fstream>
#include <vector>
#include <algorithm>
#define DIM 100001
using namespace std;
ifstream fin("zvon.in");
ofstream fout("zvon.out");
int T, N, a, b;
int D[DIM];
vector< int >L[DIM];
bool cmp(const int &a, const int &b)
{
return D[a] > D[b];
}
void DFS(int nod)
{
for(int i = 0; i < L[nod].size(); i ++)
{
DFS(L[nod][i]);
}
sort(L[nod].begin(), L[nod].end(), cmp);
for(int i = 0; i < L[nod].size(); i ++)
{
D[nod] = max(D[nod], D[ L[nod][i] ] + i + 1);
}
}
int main()
{
fin >> T;
while(T--)
{
fin >> N;
for(int i = 1; i <= N; i ++)
{
D[i] = 0;
L[i].clear();
}
for(int i = 1; i < N; i ++)
{
fin >> a >> b;
L[a].push_back(b);
}
DFS(1);
fout << D[1] << '\n';
}
return 0;
}