Well, I sat on this for a while and shared my problems:
The input object can be considered as a tree adjacency list :
var obj={0:[[0,1],[0,3],[0,4]],1:[[1,2],[1,3]],2:[[2,3],[2,5]],3:[[3,4],[3,6]],5:[[5,6]],6:[[6,5]]};
and as a result, the following is required: in fact, this is a list of all the root paths of the tree:
[0,1,2,3,4] [0,1,2,3,6] [0,1,2,5,6] [0,1,3,4] [0,1,3,6] [0,3,4] [0,3,6] [0,4]
slightly different from the result set mentioned in the question below:
[0,1,2,3,4,5,6] [0,1,2,3,6] [0,1,2,5,6] [0,1,3,4,5,6] [0,1,3,4] [0,1,3,6] [0,3,4,5,6] [0,3,6] [0,4]
Difference between the results is only whether 4 and 6 leaf nodes
Decision
Therefore, I assume that for our Tree here:
See code below. First I created a tree, and all root paths are listed from it:
.as-console-wrapper{top:0;max-height:100%!important;}