Pagini recente » Cod sursa (job #574460) | Cod sursa (job #1352818) | Cod sursa (job #1423327) | Cod sursa (job #31116) | Cod sursa (job #3250072)
#include <bits/stdc++.h>
using namespace std;
string file="darb";
ifstream fin(file+".in");
ofstream fout(file+".out");
set<int> g[100001];
vector<int> b;
int maxim=0, dmax=0;
void dfs(int i, int d)
{
b[i]=1;
if (dmax<d){
dmax=d;
maxim=i;
}
//cout<<i<<" "<<g[i].size();
for (auto j:g[i]){
if (!b[j])dfs(j, d+1);
}
}
int main()
{
int n;
fin>>n;
b.resize(n+1);
for (int i=1; i<n; i++){
int x, y;
fin>>x>>y;
g[x].insert(y);
g[y].insert(x);
//cout<<x<<" "<<y<<endl;
}
dfs(1, 0);
fill(b.begin(), b.end(), 0);
dmax=0;
dfs(maxim, 1);
fout<<dmax;
return 0;
}