Cod sursa(job #3278401)

Utilizator ShAwDoRneYNacu Gabriel ShAwDoRneY Data 19 februarie 2025 17:50:28
Problema Zvon Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#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;
}