#include using namespace std; #ifdef _RUTHEN #include "debug.hpp" #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template using V = vector; priority_queue que[200005]; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; V> G(N); rep(i, N - 1) { int x, y; cin >> x >> y; x--, y--; G[x].push_back(y); G[y].push_back(x); } auto rec = [&](auto f, int cur, int par) -> void { for (auto &nex : G[cur]) { if (nex == par) continue; f(f, nex, cur); while (!que[nex].empty()) { que[cur].push(que[nex].top()); que[nex].pop(); } } int v = 1, cnt = 0; while (!que[cur].empty() && cnt < 2) { cnt++; v += que[cur].top(); que[cur].pop(); } que[cur].push(v); return; }; rec(rec, 0, -1); int ans = que[0].top(); cout << ans << '\n'; return 0; }