#include #include using namespace std; using namespace atcoder; #define rep(i, n) REP(i, 0, n) #define REP(i, s, e) for (ll i = (s); i < (ll)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for (ll i = (ll)(s - 1); i >= (ll)(e); i--) #define all(r) r.begin(), r.end() #define rall(r) r.rbegin(), r.rend() using ll = long long; using vi = vector; using vl = vector; template bool chmax(T& a, const U& b) { if (a >= b) return false; a = b; return true; } template bool chmin(T& a, const U& b) { if (a <= b) return false; a = b; return true; } void yes_no(bool f, string yes = "Yes", string no = "No") { cout << (f ? yes : no) << "\n"; } void solve() { int n; cin >> n; vector es(n); vi deg(n); rep(i, n - 1) { int a, b; cin >> a >> b; --a; --b; es[a].emplace_back(b); es[b].emplace_back(a); deg[a]++; deg[b]++; } vi vis(n); using P = pair; segtree seg(n); rep(i, n) { seg.set(i, P((deg[i] + 1) / 2, i)); } auto dfs = [&](auto self, int cur, int par) -> void { if (vis[cur]) return; vis[cur] = 1; for (auto&& to : es[cur]) if (to != par && !vis[to]) { auto [x, _] = seg.get(to); seg.set(to, P(-1, -1)); if (x - 1 == 0) { self(self, to, cur); } } }; int ans = 0; while (1) { auto [x, i] = seg.all_prod(); if (x == -1) break; ++ans; seg.set(i, P(-1, -1)); dfs(dfs, i, -1); } cout << ans << "\n"; } int main() { cin.tie(0); ios::sync_with_stdio(false); int t = 1; // cin >> t; rep(ti, t) solve(); return 0; }