Pagini recente » Cod sursa (job #2437732) | Cod sursa (job #164610) | Cod sursa (job #2820697) | Cod sursa (job #482230) | Cod sursa (job #1611729)
#include <fstream>
#include <vector>
using namespace std;
const int N_MAX = 1e5;
ifstream fin("darb.in");
ofstream fout("darb.out");
int N;
vector<int> G[N_MAX + 5];
pair<int, int> last;
void Dfs(int node, int padre, int level) {
last = max(last, make_pair(level, node));
for (int son : G[node])
if (son != padre)
Dfs(son, node, level + 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, 0, 1);
int start = last.second;
last = make_pair(0, 0);
Dfs(start, 0, 1);
fout << last.first << "\n";
return 0;
}