Pagini recente » Cod sursa (job #1854097) | Cod sursa (job #1865521) | Cod sursa (job #1157332) | Cod sursa (job #2410368) | Cod sursa (job #2418434)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("zvon.in");
ofstream fout("zvon.out");
const int NMax = 100000;
int N, T, DP[NMax + 5];
vector <int> G[NMax + 5];
inline bool compare(int A, int B) { return A > B;}
void DFS(int Nod, int Tata)
{
vector <int> S;
for(auto Vecin : G[Nod])
if(Vecin != Tata)
DFS(Vecin, Nod), S.push_back(DP[Vecin]);
sort(S.begin(), S.end(), compare);
for(int i = 0; i < S.size(); i++)
DP[Nod] = max(DP[Nod], S[i] + i + 1);
}
int main()
{
fin >> T;
while(T--) {
fin >> N;
for(int i = 1, a, b; i < N; i++) {
fin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
DFS(1, 0); fout << DP[1] << '\n';
for(int i = 1; i <= N; i++)
DP[i] = 0, G[i].clear();
}
fin.close();
fout.close();
return 0;
}