Pagini recente » Cod sursa (job #490314) | Cod sursa (job #1792230) | Cod sursa (job #2968201) | Cod sursa (job #355502) | Cod sursa (job #2671545)
#include <fstream>
#include <vector>
#define NMAX 100005
using namespace std;
ifstream fin ("darb.in");
ofstream fout("darb.out");
int n, dist[NMAX], nodmax;
vector <int> G[NMAX];
void DFS(int nod)
{
for(auto i : G[nod])
if(!dist[i])
{
dist[i] = dist[nod] + 1;
if(dist[i] > dist[nodmax]) nodmax = i;
DFS(i);
}
}
int main()
{
fin >> n;
for(int i = 1, x, y; i < n; ++i)
{
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
fin.close();
dist[1] = 1;
DFS(1);
for(int i = 1; i <= n; ++i) dist[i] = 0;
dist[nodmax] = 1;
DFS(nodmax);
fout << dist[nodmax];
fout.close();
return 0;
}