fn dfs(cur: usize, prev: usize, paths: &Vec>, lines: &mut Vec) -> usize { let mut ret = 1usize; for &(v, idx) in paths[cur].iter() { if v == prev { continue; } let val = dfs(v, cur, paths, lines) ; lines[idx] = val; ret += val; } 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 i in 0..n-1 { let mut ab = String::new(); std::io::stdin().read_line(&mut ab).ok(); let ab: Vec = ab.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let a = ab[0]-1; let b = ab[1]-1; paths[a].push((b, i)); paths[b].push((a, i)); } let mut lines = vec![0usize; n-1]; dfs(0, 0, &paths, &mut lines); let mut result = n * n; for &v in lines.iter() { result += (n - v) * v * 2; } println!("{}", result); }