Pagini recente » Cod sursa (job #1980195) | Cod sursa (job #2635923) | Cod sursa (job #2774211) | Cod sursa (job #3194036) | Cod sursa (job #1093903)
#include <fstream>
#include <vector>
#include <cstring>
using namespace std ;
const int Nmax = 100002;
vector < int > Tree[Nmax];
int Dist[Nmax],start;
inline void Read(){
int x, y ,i ,N;
ifstream f("darb.in");
f >> N;
for(i = 1;i < N; ++i){
f >> x >> y;
Tree[x].push_back(y);
Tree[y].push_back(x);
}
f.close();
}
inline void DFS(const int node){
if(Dist[node] > Dist[start])
start = node;
for(vector < int > :: iterator it = Tree[node].begin(); it != Tree[node].end(); ++it)
if(Dist[*it]==0){
Dist[*it] = Dist[node]+1;
DFS(*it);
}
}
inline void Solve(){
Dist[1] = 1;
DFS(1);
memset(Dist,0,sizeof(Dist));
Dist[start] = 1;
DFS(start);
}
inline void Write(){
ofstream g("darb.out");
g<<Dist[start]<<"\n";
g.close();
}
int main(){
Read();
Solve();
Write();
return 0;
}