use std::io::*; fn dfs(v: usize, p: usize, ans: &mut usize, g: &Vec>) -> usize { let mut sz = 1; for &nv in g[v].iter() { if nv != p { let nsz = dfs(nv, v, ans, g); *ans += nsz * (g.len() - nsz); sz += nsz; } } *ans += sz * (g.len() - sz); sz } 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]; for _ in 0..n - 1 { let a: usize = itr.next().unwrap().parse::().unwrap() - 1; let b: usize = itr.next().unwrap().parse::().unwrap() - 1; g[a].push(b); g[b].push(a); } let mut ans = 0; dfs(0, 0, &mut ans, &g); println!("{}", ans + n * n); }