function T = maxTree(G)
% Construct a maximal tree of mapper adjacency graph 
%	T = maxTree(G)

N = size(G,1);

% Construct the downward gradient flow as a directed graph
dG = triu(G,0);

degree_in = sum(dG>0,2);
ID_multiple = find(degree_in>1);

for i=1:length(ID_multiple),
	[flow_max,id_max]= max(dG(ID_multiple(i),:));
	dG(ID_multiple(i),:) = zeros(1,N);
	dG(ID_multiple(i),id_max)=G(ID_multiple(i),id_max);
end
	
T = dG;
