Problem 834 · Hard

Sum of Distances in Tree

Root the tree once, gather subtree sizes and distance sums upward, then re-root the answer downward.

Open the interactive visualisation