Tuesday common C++ interview problem: Sum of distances to all nodes
Given a tree with n nodes, represented as a graph using a neighbourhood map, calculate the sum of distances to all other nodes for each node.
The node ids are in the range [0,n).
Solve it yourself: https://compiler-explorer.com/z/5nj1ejG5G
Solution: https://compiler-explorer.com/z/59zxjq1ca