use std::io::*; 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]; let mut deg = vec![0; n]; for _ in 0..n - 1 { let a = itr.next().unwrap().parse::().unwrap() - 1; let b = itr.next().unwrap().parse::().unwrap() - 1; g[a].push(b); deg[b] += 1; } let mut start = 0; for i in 0..n { if deg[i] == 0 { start = i; } } let mut q = std::collections::VecDeque::new(); let mut dist = vec![0; n]; q.push_back(start); let mut ans = 0; while let Some(v) = q.pop_front() { ans += dist[v] * (dist[v] + 1) / 2; for &nv in g[v].iter() { dist[nv] = dist[v] + 1; q.push_back(nv); } } println!("{}", ans); }