function ParentList = ChildrenList2ParentList(ChildrenList)
% ParentList = ChildrenList2ParentList(ChildrenList)
%Input: ChildrenList: m + 1 column matrix (of integers) for a rooted tree
%Output: ParentList: a two column matrix giving the parent of each vertex
[n s] = size(ChildrenList); %n = number of vertices
ParentList = zeros(n,2);
ParentList(:,1) = ChildrenList(:,1);
ParentList(1,2) = 0; %root has no parent
for i = 2:n %find parent of each nonroot vertex
    [parentInd childNumberp1] = find(ChildrenList(:,2:s)==ParentList(i,1));
    ParentList(i,2) = ParentList(parentInd,1);
end
    