Daniel@0: function [T, pre, post, cycle] = mk_rooted_tree(G, root) Daniel@0: % MK_ROOTED_TREE Make a directed tree pointing away from root Daniel@0: % [T, pre, post, cycle] = mk_rooted_tree(G, root) Daniel@0: Daniel@0: n = length(G); Daniel@0: T = sparse(n,n); % not the same as T = sparse(n) ! Daniel@0: directed = 0; Daniel@0: [d, pre, post, cycle, f, pred] = dfs(G, root, directed); Daniel@0: [junk, pre2] = sort(d); Daniel@0: assert(isequal(pre, pre2)) Daniel@0: [junk, post2] = sort(f); Daniel@0: assert(isequal(post, post2)); Daniel@0: %[d, pre, post, cycle, f, pred] = dfs(G, [], directed); Daniel@0: for i=1:length(pred) Daniel@0: if pred(i)>0 Daniel@0: T(pred(i),i)=1; Daniel@0: end Daniel@0: end Daniel@0: