calculates all-pairs shortest paths or shortest paths from a single node