Cod sursa(job #1887506)

Utilizator FloareaCucura Floarea Ludovica Floarea Data 21 februarie 2017 17:13:32
Problema Zvon Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <iostream>
#include <fstream >
#include <vector >
#include <limits.h>

using namespace std;

ifstream fin("zvon.in");
ofstream fout("zvon.out");;

const int maxn=100000;
int nivel[maxn];
vector <int> a[maxn];
bool viz[maxn];

int dfs (int nod, int niv)
{
    nivel[nod]=niv;
    viz[nod]=1;
    for(int i=1; i<=a[nod][i]; ++i)
        if (!viz[a[nod][i]])
       return  dfs(a[nod][i], niv+1);
}

int main ()
{   int nivel[maxn];
    int t, n, x,y;
    int maxim=INT_MIN;
    fin>>t;
    for(int i=1; i<=t; ++i)
    {
      fin>>n;
      for(int j=1; j<n; ++j)
      {
        fin>>x>>y;
        a[x].push_back(y);
        a[y].push_back(x);
      }
     dfs (1,1);
     for(int x=1; x<=n; ++x)
        if(nivel[x]>maxim)
        maxim=nivel[x];
     fout<< maxim;
    }
    return 0;
}