Problem: For a tree with n vertices. Every vertex has a value in range [1, c]. We define d(u, v) is number of distinct vertices's value on simple path from u to v, and . We have to calculate all sum(i), 1 ≤ i ≤ n.
Constraints: 1 ≤ n ≤ 100000, 1 ≤ c ≤ 300000.
Do you have any idea?