Pagini recente » Cod sursa (job #1821945) | Cod sursa (job #177803) | Cod sursa (job #1488895) | Cod sursa (job #1435567) | Cod sursa (job #2039346)
#include <fstream>
#include <vector>
using namespace std;
/*ifstream cin ("input");
ofstream cout ("output");*/
ifstream cin ("darb.in");
ofstream cout ("darb.out");
vector < vector < int > > gr (100100);
vector < int > used (100100);
void dfs (int root , int dist , int &MAX , int &pos){
if (MAX < dist){
MAX = dist;
pos = root;
}
for (auto &x : gr[root]){
if (!used[x]){
used[x] = true;
dfs(x , dist + 1 , MAX , pos);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int nodes;
cin>>nodes;
for (int i=1; i<nodes; i++){
int a , b;
cin>>a>>b;
gr[a].push_back(b);
gr[b].push_back(a);
}
int MAX = 1;
int pos;
dfs (1 , 1 , MAX , pos);
for (auto &x : used){
x = false;
}
MAX = 1;
int inutil;
dfs (pos , 1 , MAX , inutil);
cout<<MAX;
return 0;
}