Problem 3786 · Hard

Total Sum of Interaction Cost in Tree Groups

Measure the path length between every pair of nodes that share a group label and add the lengths up.

Open the interactive visualisation