第1个回答 2018-12-18
g = Graph[{s <-> a, s <-> b, s <-> c, a <-> b, b <-> c, a <-> d,
b <-> d, c <-> e, b <-> e, d <-> e, d <-> t, e <-> t},
EdgeWeight -> {2, 8, 4, 2, 2, 7, 9, 8, 3, 2, 4, 7}];
Map[FindShortestPath[g, s, #] &, {a, b, c, d, e, t}]
Map[GraphDistance[g, s, #] &, {a, b, c, d, e, t}]
用Mathematica求得s到各点的最短路径:
{{s, a}, {s, a, b}, {s, c}, {s, a, d}, {s, a, b, e}, {s, a, d, t}}
s到各点的最短距离:{2., 4., 4., 9., 7., 13.}