Pagini recente » Cod sursa (job #934248) | Cod sursa (job #1656823) | Cod sursa (job #2936278) | Cod sursa (job #3217762) | Cod sursa (job #1689357)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream f("darb.in");
ofstream g("darb.out");
const int Nmax = 100005;
int n, Level[Nmax];
vector <int> G[Nmax];
void DFS(int nod, int tata)
{
for(int i = 0; i < (int)G[nod].size(); i++)
{
int vecin = G[nod][i];
if(vecin == tata) continue;
Level[vecin] = Level[nod]+1;
DFS(vecin, nod);
}
}
bool Crit(int a, int b)
{
return a>b;
}
int main()
{
f>>n;
for(int i = 1; i <= n; i++)
{
int x, y;
f>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
Level[1] = 1;
DFS(1,0);
sort(Level+1, Level+1+n, Crit);
g<<(Level[1] + Level[2] -1)<<'\n';
return 0;
}