Pagini recente » Cod sursa (job #773378) | Cod sursa (job #3003704) | Cod sursa (job #737750) | Cod sursa (job #326700) | Cod sursa (job #2551413)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("darb.in");
ofstream fout("darb.out");
int n, ma, T[100001], Dp[100001]; // Dp[x] - lantul maxim care porneste de la x si merge in jos pe arbore
vector<int> G[100001];
void Dfs(int x)
{
Dp[x] = 1;
for (int y : G[x])
{
if (y != T[x])
{
T[y] = x;
Dfs(y);
ma = max(ma, Dp[x] + Dp[y]);
Dp[x] = max(Dp[x], Dp[y] + 1);
}
}
}
int main()
{
fin >> n;
for (int i = 1; i < n; ++i)
{
int x, y;
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
Dfs(1);
fout << ma;
return 0;
}