Given a weighted tree with n nodes. We have to find for each node sum of squares of distances towards every other node. Complexity should be O(n).
I am looking for an algorithm to solve the problem. No realisation needed. I thought that Dijkstra would be useful but it’s basically O(n^2) so I’m out of ideas.