Quantcast
Channel: Question and Answer » trees
Viewing all articles
Browse latest Browse all 36

Sum of squares of distances on a weighted graph O(n)

$
0
0

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.


Viewing all articles
Browse latest Browse all 36

Trending Articles