Pagini recente » Cod sursa (job #3178601) | Cod sursa (job #2759255) | Cod sursa (job #215508) | Cod sursa (job #3184146) | Cod sursa (job #1479290)
#include<fstream>
#include<vector>
using namespace std;
ifstream in("darb.in");
ofstream out("darb.out");
const int nmax = 100006;
int n, dmax, nodmax;
vector<int> vecini[nmax];
bool viz[nmax];
void dfs(int x, int dist)
{
viz[x] = 1;
if(dist>dmax)
{
nodmax = x;
dmax = dist;
}
for(int i = 0; i<(int)vecini[x].size(); i++)
{
if(viz[vecini[x][i]]==0)
dfs(vecini[x][i], dist + 1);
}
}
int main(){
int player_unu=0;
in>>n;
for(int i = 1; i<n; i++)
{
int a, b;
in>>a>>b;
vecini[a].push_back(b);
vecini[b].push_back(a);
}
dfs(1, 0);
for(int i = 1; i<=n; i++)
viz[i] = 0;
dfs(nodmax, 0);
out<<dmax + 1<<'\n';
return player_unu;
}