func main() class Node() +var parent: Node +var children: []Node +var depth: int +var num: int *func ctor() do me.parent :: null do me.children :: #[0]Node end func +func calcDepth() if(me.parent =& null) do me.depth :: 1 else do me.depth :: me.parent.depth + 1 end if for i(0, ^me.children - 1) do me.children[i].calcDepth() end for end func +func calcNum() if(^me.children = 0) do me.num :: 0 ret end if for i(0, ^me.children - 1) do me.children[i].calcNum() do me.num :+ me.children[i].num + 1 end for end func end class var n: int :: cui@inputInt() var nodes: []Node :: #[n]Node for i(0, n - 1) do nodes[i] :: #Node end for var as: []int :: #[n - 1]int var bs: []int :: #[n - 1]int for i(0, n - 2) var a: int :: cui@inputInt() - 1 var b: int :: cui@inputInt() - 1 do as[i] :: a do bs[i] :: b do nodes[a].children :~ [nodes[b]] do nodes[b].parent :: nodes[a] end for var root: Node for i(0, n - 1) if(nodes[i].parent =& null) do root :: nodes[i] end if end for do root.calcDepth() do root.calcNum() var ans: int :: 0 for i(0, n - 2) do ans :+ nodes[as[i]].depth * (nodes[bs[i]].num + 1) end for do cui@print("\{ans}\n") end func