#include using namespace std; int main() { int N; cin >> N; vector> adj(N); for (int i = 0; i < N - 1; i++) { int u, v; cin >> u >> v; adj[--u].push_back(--v); adj[v].push_back(u); } function *(int, int)> dfs = [&](int a, int p) -> priority_queue * { priority_queue *S = new priority_queue(); for (auto x : adj[a]) if (x != p) { priority_queue *T = dfs(x, a); if (S->size() < T->size()) swap(S, T); while (!T->empty()) S->push(T->top()), T->pop(); delete T; } int v = 1; for (int i = 0; i < 2; i++) if (!S->empty()) v += S->top(), S->pop(); S->push(v); return S; }; auto S = dfs(0, -1); cout << S->top() << endl; delete S; return 0; }