#include #include #include int main() { int N; std::cin >> N; std::vector> g(N); for (int i = 0, u, v; i < N - 1; i++) { std::cin >> u >> v, u--, v--, g[u].push_back(v), g[v].push_back(u); } std::vector> memo(N, std::vector(2, -1)); auto dp = [&](auto&& self, const int s, const int p, const bool ok)->int { if (memo[s][ok] != -1) { return memo[s][ok]; } int ans = ok, ans2 = 0; for (const int to : g[s]) { if (to == p) { continue; } ans += self(self, to, s, false), ans2 += self(self, to, s, true); } return memo[s][ok]=std::max(ans, ans2); }; std::cout << dp(dp, 0, -1, true) << std::endl; return 0; }