0834. Sum of Distances in Tree
Last updated
Last updated
**Input:** n = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
**Output:** [8,12,6,10,10,10]
**Explanation:** The tree is shown above.
We can see that dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5)
equals 1 + 1 + 2 + 2 + 2 = 8.
Hence, answer[0] = 8, and so on.**Input:** n = 1, edges = []
**Output:** [0]**Input:** n = 2, edges = [[1,0]]
**Output:** [1,1]