Problem 834 · Hard
Root the tree once, gather subtree sizes and distance sums upward, then re-root the answer downward.
Open the interactive visualisation