Pagini recente » Cod sursa (job #26844) | Cod sursa (job #1976593) | Cod sursa (job #2952445) | Cod sursa (job #2782445) | Cod sursa (job #2375864)
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
ifstream f ("darb.in");
ofstream g ("darb.out");
int n, x , y, Max, nod;
bool a[100001];
vector<int>G[100001];
void dfs (int x, int t)
{
a[x]=1;
if (t>Max)
{
Max=t;
nod=x;
}
for (int i=0; i<G[x].size(); i++)
{
if (!a[G[x][i]]) dfs(G[x][i], t+1);
}
}
int main ()
{
f >> n;
for (int i=1; i<n; i++)
{
f >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(1, 1);
memset(a, 0, sizeof(a));
dfs(nod, 1);
g << Max;
return 0;
}