Skip to main content
1 of 3
user46831
  • 663
  • 3
  • 8

Thanks for that. Impressive. An alternative that might be better reflected in the documentation is to use FindShortestPath.

(* FindShortestPath returns a procedure *)
With[{pathfunc=FindShortestPath[smallgraph, 1, All],
     (* Construct weight rules for the graph *)
      edgeweights =Thread[Rule[EdgeList[smallgraph],
                               PropertyValue[smallgraph,EdgeWeight]]]},
     (* For each vertex, recover the path and its length *)
     Map[With[{path=EdgeList[PathGraph[pathfunc[#],
                                     DirectedEdges->True]]},
                {# , path, Plus@@path/.edgeweights}]&,
         VertexList[smallgraph]]]

Alternatively, just return the edges of the tree...

user46831
  • 663
  • 3
  • 8