Description:
描述:
This is a very popular interview problem to find all pair shortest paths in any graph. This problem has been featured in interview rounds of Samsung.
这是一个非常流行的面试问题,用于在任何图中找到所有对最短路径。 该问题已在三星的采访回合中提到。
Problem statement:
问题陈述:
Given a weighted directed graph, the problem is to find the shortest distances between every pair of vertices. The Graph is represented by an adjacency matrix, and any cell arr[i][j] denotes the weight of the edge (path cost) from node i to node j (if it exists) else INF.
给定一个加权有向图,问题在于找到每对顶点之间的最短距离。 该图由邻接矩阵表示,任何单元格arr [i] [j]表示从节点i到节点j (如果存在)或其他INF的边的权重(路径成本)。
Input: N=5
输入: N = 5
Adjacency matrix:
邻接矩阵:
Example:
例:
So the graph for the above input is,
因此,上述输入的图形为