#![allow(unused_imports)] use std::cmp::*; use std::collections::*; fn main() { let n = read::(); let mut edges = vec![vec![]; n]; let mut rev_edges = vec![vec![]; n]; for i in 0..n - 1 { let v = read_vec::(); let (a, b) = (v[0] - 1, v[1] - 1); edges[a].push(b); rev_edges[b].push(a); } let root = (0..n).find(|&x| rev_edges[x].is_empty()).unwrap(); let mut pre_order = vec![]; dfs(root, &edges, &mut pre_order); pre_order.reverse(); let mut count = vec![0; n]; let mut dp = vec![0; n]; for ti in pre_order { if edges[ti].is_empty() { continue; } for &ci in &edges[ti] { count[ti] += 1 + count[ci]; dp[ti] += dp[ci]; } dp[ti] += count[ti]; } let ans = dp.iter().sum::(); println!("{}", ans); } fn dfs(cur: usize, edges: &Vec>, pre_order: &mut Vec) { pre_order.push(cur); for &to in edges[cur].iter() { dfs(to, edges, pre_order); } } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }