add distances for each node.