Pagini recente » Cod sursa (job #961203) | Cod sursa (job #1542311) | Cod sursa (job #3279282) | Cod sursa (job #2659023) | Cod sursa (job #3278401)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("zvon.in");
ofstream fout("zvon.out");
void DFS(int node, int depth, int &maxDepth, vector<vector<int>> &graph) {
for(auto neighbor : graph[node]) {
DFS(neighbor, depth+1, maxDepth, graph);
}
maxDepth = max(maxDepth, depth);
}
int main() {
int T;
fin >> T;
while(T--) {
int N;
fin >> N;
if(N == 1) {
fout << 0 << '\n';
continue;
}
vector<vector<int>> graph(N+1, vector<int>());
for(int i=1; i<N; i++) {
int x,y;
fin >> x >> y;
graph[x].push_back(y);
}
int maxDepth = 1;
DFS(1, 1, maxDepth, graph);
fout << maxDepth << '\n';
}
return 0;
}