Pagini recente » Cod sursa (job #2180100) | Cod sursa (job #2206621) | Cod sursa (job #1329459) | Cod sursa (job #2927408) | Cod sursa (job #1372621)
#include <iostream>
#include <fstream>
#include <vector>
#define Nmax 100001
#define oo 1000000000
using namespace std;
ifstream fin("darb.in");
ofstream fout("darb.out");
vector<int> G[Nmax];
int use[Nmax];
int max1,max2,nodmax;
int n;
void read()
{
fin>>n;
int i;
for(i=1;i<n;i++)
{
int a,b;
fin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
}
}
void DFS(int nod,int depth)
{
use[nod]=1;
for(unsigned int i=0;i<G[nod].size();i++)
if(!use[G[nod][i]])
{
DFS(G[nod][i],depth+1);
}
if(depth>max1)
max1=depth,nodmax=nod;
}
int main()
{
read();
max1=-oo;
DFS(1,1);
max1=-00;
for(int i=1;i<=n;i++)
use[i]=0;
DFS(nodmax,1);
fout<<max1;
return 0;
}