最佳答案
1 和 0 的邻接矩阵只是无向图的表示。要获取未加权图的任意两个顶点之间的距离,可以使用 breadth first search .
假设您有一个 n
by n
矩阵:
for each vertex i:
initialize an nxn matrix M
run breadth-first search starting at i
copy distances into row i of M
return M
关于将邻接矩阵转换为距离或跳跃矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10079876/