%% Shortest Paths from Specified Source Node
% Find the shortest paths from a source node to each of the other reachable nodes in a graph, and plot the results.
% Create a directed graph.

s = [1 1 2 3 3 4 4 6 6 7 8 7 5];
t = [2 3 4 4 5 5 6 1 8 1 3 2 8];
G = digraph(s,t)

%
% Calculate the shortest paths from node 1 to each of the other reachable nodes in the graph. Then, plot the resulting tree on top of the graph.

TR = shortestpathtree(G,1);
p = plot(G);
highlight(p,TR,'EdgeColor','r')

% Since there is no path from node 1 to node 7, node 7 is disconnected from the tree.
% Copyright 2015 The MathWorks, Inc.