Loading problem…
An undirected tree has n nodes labeled 0 through n - 1 and edges given as pairs [a, b]. The distance between two nodes is the number of edges in their unique path.
Return an array answer where answer[node] is the sum of its distances to every other node. Do not change edges. A node contributes distance zero to itself.
Example 1:
Example 2:
Example 3: