#include #include #include using namespace std; vector adj[100100]; int memo[2][100100]; int calc(int i, int use, int p = -1) { if (memo[use][i] >= 0) return memo[use][i]; int sum = use; for (int j : adj[i]) if (j != p) sum += use ? calc(j, 0, i) : max(calc(j, 0, i), calc(j, 1, i)); // cerr << use << ' ' << i << ' ' << sum << endl; return memo[use][i] = sum; } int main() { int n; cin >> n; for (int i = 1; i < n; i++) { int x, y; scanf(" %d %d", &x, &y); adj[x].push_back(y); adj[y].push_back(x); } fill(memo[0], memo[0] + n + 1, -1); fill(memo[1], memo[1] + n + 1, -1); cout << max(calc(1, 1), calc(1, 0)) << endl; }