
function [tree,dist]=find_span_tree2(dir_edges,out_list,p)
   K=size(out_list,1);
   deg=out_list(:,1);
   dist=-ones(K,1);
   dist(p)=0;
   tree(p)=0;
   num=deg(p);
   list=out_list(p,2:num+1);
   parent=p*ones(1,num);
   counter=0;
   while num>0
       counter=counter+1;
       new_num=0;
       new_list=[];
       new_parent=[];
       for j=1:num
           e=list(j);
	   v=dir_edges(e,2);
           if dist(v)==-1
              dist(v)=counter;
              tree(v)=parent(j);
              row=out_list(v,2:out_list(v,1)+1);
              new_num=new_num+length(row);
              new_list=[new_list,row];
              new_parent=[new_parent,v*ones(1,length(row))];
           end % if
       end % for j
       list=new_list;
       num=new_num;
       parent=new_parent;
   end % while
return 
