Pagini recente » Cod sursa (job #1434320) | Cod sursa (job #1237480) | Cod sursa (job #334752) | Cod sursa (job #641398) | Cod sursa (job #1368518)
#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;
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);
}
int d=depth;
if(depth>=max1)
max2=max1,max1=depth;
else
if(depth>max2)
max2=depth;
}
int main()
{
read();
max1=-oo,max2=-oo;
DFS(1,1);
fout<<max1+max2-1;
return 0;
}