use std::collections::{VecDeque, HashSet}; const INF: usize = 1usize << 60; fn bfs(start: usize, paths: &Vec>) -> Vec { let mut ret = vec![INF; paths.len()]; ret[start] = 0usize; let mut deque = VecDeque::new(); deque.push_back(start); while let Some(u) = deque.pop_front() { for &v in paths[u].iter() { if ret[v] < INF { continue; } ret[v] = ret[u] + 1; deque.push_back(v); } } ret } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut paths = vec![vec![]; n]; for _ in 0..n-1 { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let a = temp[0]-1; let b = temp[1]-1; paths[a].push(b); paths[b].push(a); } let n3 = paths.iter().filter(|&v| v.len() > 2).count(); if n3 > 1 { println!("No"); } else if n3 == 0 { println!("Yes"); } else { let idx = (0..n).filter(|&i| paths[i].len() > 2).nth(0).unwrap(); let dists1 = bfs(idx, &paths); let dist_pattern = (0..n).filter(|&i| paths[i].len() == 1).map(|i| dists1[i]).collect::>().len(); if dist_pattern == 1 && paths.iter().filter(|&v| v.len() > 2).count() <= 1 { println!("Yes"); } else { println!("No"); } } }