use std::io::{self, read_to_string}; fn main() { let mut x = String::new(); io::stdin().read_line(&mut x).unwrap(); // let mut tmp= x.split_whitespace().map(|a|a.parse::().unwrap() ); // let size:usize=x.parse().unwrap(); let size = x .split_whitespace() .map(|a| a.parse::().unwrap()) .next() .unwrap(); x.clear(); let mut pairs = Vec::<(u32, u32)>::new(); for i in 0..size - 1 { io::stdin().read_line(&mut x).unwrap(); let mut tmp = x.split_whitespace().map(|a| a.parse::().unwrap()); pairs.push((tmp.next().unwrap(), tmp.next().unwrap())); x.clear(); } let swap = pairs .iter() .map(|(a, b)| if a <= b { (*a, *b) } else { (*b, *a) }); let mut pairs: Vec<(u32, u32)> = swap.collect::>(); pairs.sort_by(|&a, &b| a.0.cmp(&b.0)); let mut t_node: Vec = Vec::new(); let mut last=1; let mut node: Vec = Vec::new(); for i in 0..t_node.len(){ if last+1!=t_node[i].number{ node.push(Node{ number:last+1, to:vec!(last+2) }) } node.push(t_node[i].clone()); last=t_node[i].number; } let mut lastone = 1; let mut tmp_to = Vec::::new(); for i in pairs.iter() { if i.0 == lastone { tmp_to.push(i.1) } else { node.push(Node { number: (i.0), to: (tmp_to.clone()), }); tmp_to.clear(); lastone = i.0; tmp_to.push(i.1) } } for i in 0..node.len() { let mut count = 0; if i >= 2 { count += 1; } if i + 2 < node.len() { count += 1; } if i != 0 { count+=node[i-1].to.len()-1; } println!("{}",count); } } #[derive(Clone)] struct Node { number: u32, to: Vec, }