Pagini recente » Cod sursa (job #150435) | Istoria paginii runda/becreative2/clasament | Cod sursa (job #2933214) | Cod sursa (job #1391269) | Cod sursa (job #2954153)
#include<bits/stdc++.h>
using namespace std;
ifstream F("darb.in");
ofstream G("darb.out");
vector<int> v[100001];
int n,i,j,w[100001],m;
bool u[100001];
void A(int i)
{
int j,k;
for(k=v[i].size(),u[i]=1,j=0;j<k;++j)
if(!u[v[i][j]])
w[v[i][j]]=w[i]+1,A(v[i][j]);
}
int main()
{
for(F>>n;F>>i>>j;v[i].push_back(j),v[j].push_back(i));
for(w[1]=1,A(1),i=1;i<=n;u[i]=w[i]=0,++i)
if(w[i]>m)
m=w[i],j=i;
for(w[j]=1,A(j),m=0,i=1;i<=n;m=max(m,w[i++]));
return G<<m,0;
}