calculates distance to each path