MathTop

graph_shortest_path 函数

返回两个顶点之间的一条最短路径。

语法

  • GraphTheory:-ShortestPath(edges, source, target)
  • graph_shortest_path(edges, source, target)

参数与选项

edges形如 [[u, v], ...] 的边列表。
source起点顶点。
target终点顶点。

示例

  1. 最短路径GraphTheory:-ShortestPath([[a, b], [b, c], [c, a], [c, d]], a, d)返回 [a, c, d]。