#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector> g(n); for(int i = 1; i < n; ++i){ int u, v; cin >> u >> v; --u, --v; g[u].emplace_back(v); g[v].emplace_back(u); } vector> dp(n, vector(2, -1)); auto func = [&](auto&& self, int v, int i, int par = -1) -> int { if(dp[v][i] != -1) return dp[v][i]; int res = i; for(int ch : g[v]){ if(ch == par) continue; if(i) res += max(self(self, ch, 0, v), self(self, ch, 1, v) - 1); else res += max(self(self, ch, 0, v), self(self, ch, 1, v)); } return dp[v][i] = res; }; cout << max(func(func, 0, 0), func(func, 0, 1)) << endl; return 0; }