let () = Scanf.scanf "%d\n" @@ fun n ->
  let es = Array.init (n - 1) @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun u v -> u, v in
  let vs =
    Array.fold_left ( + ) 0 @@
    Array.init n @@ fun i -> (i + 1) * (n - i) in
  Printf.printf "%d\n" @@
  Array.fold_left (fun acc (u, v) ->
    let [u; v] = List.sort compare [u; v] in
    acc - u * (n - v + 1)) vs es