Cod sursa(job #2780693)

Utilizator Edyci123Bicu Codrut Eduard Edyci123 Data 7 octombrie 2021 18:20:34
Problema Zvon Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>
#define DIM 100005

using namespace std;

ifstream f("zvon.in");
ofstream g("zvon.out");

int t, n, ans;
vector <int> edges[DIM];

void dfs(int nod, int niv)
{
    ans = max(ans, niv);
    for(auto k : edges[nod])
        dfs(k, niv + 1);
}

int main()
{
    f >> t;

    for(; t; t--)
    {
        f >> n;
        if(n == 1)
        {
            g << 0 << "\n";
            continue;
        }
        for(int i = 1; i < n; i++)
        {
            int x, y;
            f >> x >> y;
            edges[x].push_back(y);
        }

        dfs(1, 1);
        g << ans << "\n";

        for(int i = 1; i <= n; i++)
            edges[i].clear();
        ans = 0;
    }



    return 0;
}