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 idx1 = (0..n).filter(|&i| paths[i].len() == 1).nth(0).unwrap(); let idx2 = (0..n).filter(|&i| paths[i].len() == 1).nth(1).unwrap(); let dists1 = bfs(idx1, &paths); let dists2 = bfs(idx2, &paths); let mut dist_pattern = (0..n).filter(|&i| i != idx1 && paths[i].len() == 1).map(|i| dists1[i]).collect::>(); (0..n).filter(|&i| i != idx2 && paths[i].len() == 1).map(|i| dists2[i]).for_each(|v| { dist_pattern.insert(v); }); if dist_pattern.len() == 1 && paths.iter().filter(|&v| v.len() > 2).count() <= 1 { println!("Yes"); } else { println!("No"); } }