Total Depth
Rooted at node 1, print the sum of the depths of all nodes (the root has depth 0).
Input: the first line has N; each of the next N−1 lines has an edge u v.
Output: the sum of all node depths.
Constraints:
- 1 ≤ N ≤ 105
Sample Tests
Input 1
4 1 2 2 3 2 4
Output 1
5
Input 2
1
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.