Note that our shortest-path algorithm is designed for one start node and a set of target nodes. Therefore, if the number of safe rooms is less than the number of target rooms, it is more efficient to use the shortest-path algorithm to compute the minimum costs of paths in a reverse direction, the transpose of the adjacency matrix must be used as the “adjacency” matrix in the shortest-path algorithm.