Pagini recente » Cod sursa (job #1611400) | Cod sursa (job #579553) | Cod sursa (job #1095241) | Cod sursa (job #3032773) | Cod sursa (job #2916605)
/**
* author: R0L3eX
* created: 30.07.2022 19:32:03
* quote: Claustrophobic? Who would ever be afraid of Santa Clause?
**/
#include "bits/stdc++.h"
using namespace std;
#if defined(ONPC)
#include "bits/debug.h"
#endif
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int mxN = 2e5;
const int INF = INT_MAX;
const char nl = '\n';
vector<vector<int>> adj;
ifstream fin("darb.in");
ofstream fout("darb.out");
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
fin >> n;
adj = vector<vector<int>>(n);
for (int i = 0; i < n - 1; ++i) {
int a, b;
fin >> a >> b;
--a, --b;
adj[a].push_back(b);
adj[b].push_back(a);
}
array<int, 3> last;
queue<array<int, 3>> Q;
// node from depth
Q.push({0, 0, 0});
while (!Q.empty()) {
array<int, 3> P = Q.front();
last = P;
Q.pop();
for (int u : adj[P[0]]) {
if (u == P[1]) continue;
Q.push({u, P[0], P[2] + 1});
}
}
Q.push({last[0], last[0], 0});
while (!Q.empty()) {
array<int, 3> P = Q.front();
last = P;
Q.pop();
for (int u : adj[P[0]]) {
if (u == P[1]) continue;
Q.push({u, P[0], P[2] + 1});
}
}
fout << last[2] + 1 << nl;
}