Merge tree branches by a list of indices (46.3 KB)

Hello wizards!

I have a situation where I got stuck… What I need to do is take a tree with N number of branches and merge 2, 3 or more of those branches (in various combinations) according to a list of indices in order to end up with a new tree having the same number of branches (N).

As a toy model:
Original tree: {0};{1};{2);{3};{4} (each branch has 3 items - total number of items: 15)
Merging list: 0,2; 1,3,4; 0,1; 2,3,4; 3,4
Result tree: {A};{B};{C);{D};{E} where {A}={0}+{2}; {B}={1}+{3}+{4}; {C}={0}+{1}; {D}={2}+{3}+{4}; {E}={3}+{4}
Resulting new tree has a total of 30 items in this example.

Any ideas are welcome!

This could be one way. (52.0 KB)

thank you @HS_Kim ! works like a charm!