Pagini recente » Cod sursa (job #1369683) | Cod sursa (job #2775669) | Cod sursa (job #1326888) | Cod sursa (job #1715812) | Cod sursa (job #1354425)
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
ifstream in("darb.in");
ofstream out("darb.out");
vector< vector<int> > tree;
vector<int> v;
int n,last;
void df(int x)
{
for(vector<int>::iterator i=tree[x].begin();i!=tree[x].end();i++)
if(v[*i]==-1)
{
v[*i]=v[x]+1;
if(v[*i]>v[last])last=*i;
df(*i);
}
}
int main()
{
in>>n;
tree=vector< vector<int> >(n+1);
for(int i=1;i<n;i++)
{
int x,y;
in>>x>>y;
tree[x].pb(y);
tree[y].pb(x);
}
v=vector<int>(n+1,-1);
v[1]=1;
df(1);
v=vector<int>(n+1,-1);
v[last]=1;
df(last);
out<<v[last]<<'\n';
return 0;
}