Calculate the shortest path for every node  in adjacency matrix.