use proconio::{input, marker::Usize1}; fn main() { input! { n:usize, uv:[(Usize1,Usize1);n-1], } let mut g = vec![vec![]; n]; for &(u, v) in uv.iter() { g[u].push(v); g[v].push(u); } let mut dp = vec![[0; 2]; n]; for i in 0..n { dp[i][1] = 1; } f(0, n, &g, &mut dp); let ans = dp[0][0].max(dp[0][1]); println!("{}", ans); } fn f(crr: usize, pre: usize, g: &Vec>, dp: &mut Vec<[usize; 2]>) { for &nxt in g[crr].iter() { if nxt == pre { continue; } f(nxt, crr, g, dp); dp[crr][0] += dp[nxt][0].max(dp[nxt][1]); dp[crr][1] += dp[nxt][0].max(dp[nxt][1] - 1); } }