Pagini recente » Cod sursa (job #1180354) | Cod sursa (job #2322590) | Cod sursa (job #2438541) | Cod sursa (job #1120264) | Cod sursa (job #2885778)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("darb.in");
ofstream fout("darb.out");
vector<int> G[100002];
int nivel, nivelmaxim, nod, vis[100002];
void DFS(int x)
{
vis[x] = 1;
for(auto w : G[x])
if(vis[w] == 0)
{
vis[w] = 1;
nivel++;
DFS(w);
if(nivel > nivelmaxim)
{
nivelmaxim = nivel;
nod = w;
}
nivel--;
}
}
int main()
{
int n, i, x, y;
fin >> n;
for(i = 1; i < n; i++)
{
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
DFS(1);
for(i = 1; i <= n; i++)
vis[i] = 0;
DFS(nod);
fout << nivelmaxim + 1;
return 0;
}