#include // #include using namespace std; // using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i; using vvi = vector>; template inline void vin(vector& v) { rep(i, v.size()) cin >> v.at(i); } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template inline void drop(T x) { cout << x << endl; exit(0); } template void vout(vector v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; using pint = pair>; using vp = vector; vector> G; void make_graph(int N) { G.resize(N); int x, y; rep(i, N-1) { cin >> x >> y; x--, y--; G[x].push_back(y); G[y].push_back(x); } } pint rec(int x, int from) { vi v; priority_queue q; lint y; for (auto t : G[x]) { if (t == from) continue; priority_queue p; tie(y, p) = rec(t, x); while (!p.empty()) { q.push(p.top()); p.pop(); } v.pb(y); } if (v.size() == 0) return {1, q}; sort(all(v), greater()); rep(i, v.size()) { if (i <= 1) { if (v[i]%2 == 0) { v[i]--; q.push(1); } } else { q.push(v[i]); } } if (v.size() == 1) { if (!q.empty()) { v.pb(q.top()); q.pop(); return {v[0]+v[1]+1, q}; } else return {v[0]+1, q}; } else return {v[0]+v[1]+1, q}; } int main() { lint N; cin >> N; make_graph(N); cout << rec(0, -1).first << '\n'; }