use std::io::*; fn dfs(v: usize, p: usize, g: &Vec>) -> usize { let mut res = 1; for &nv in g[v].iter() { if nv != p { res += dfs(nv, v, g); } } res } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let mut g: Vec> = vec![Vec::new(); n]; let mut deg: Vec = vec![0; n]; for _ in 0..n - 1 { let a: usize = itr.next().unwrap().parse::().unwrap() - 1; let b: usize = itr.next().unwrap().parse::().unwrap() - 1; deg[a] += 1; deg[b] += 1; g[a].push(b); g[b].push(a); } let mut big = n; for i in 0..n { if deg[i] > 2 { if big != n { println!("No"); return; } big = i; } } if big == n { println!("Yes") } else { let mut same = n; let mut ok = true; for &v in g[big].iter() { if same == n { same = dfs(v, big, &g); } else { ok &= same == dfs(v, big, &g); } } if ok { println!("Yes"); } else { println!("No"); } } }