Pagini recente » Cod sursa (job #704213) | Cod sursa (job #470862) | Cod sursa (job #1902915) | Cod sursa (job #530282) | Cod sursa (job #3136986)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
vector<int> v[100001];
int nivelmax, nodmax;
void dfs(int nod, int tata, int nivel) {
if (nivel > nivelmax) {
nodmax = nod;
nivelmax = nivel;
}
for (int i: v[nod]) {
if (i != tata) {
dfs(i, nod, nivel + 1);
}
}
}
int main() {
ifstream fin("darb.in");
ofstream fout("darb.out");
int n;
fin >> n;
for (int i = 1; i < n; i++) {
int a, b;
fin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
dfs(1, 0, 1);
dfs(nodmax, 0, 1);
fout << nivelmax;
fin.close();
fout.close();
return 0;
}