Group > Flatten > Reduce > Ungroup - how to retain Data structure?

Many points are structured in an irregular 2-layer data tree. Structure as seen below:

{0;B} has 14 branches
{1;B} has 14 branches
{2;B} has 14 branches
{3;B} has 14 branches
{4;B} has 1 branch

each branch has 1 grouped item with same amount of points inside. I wanted these points to be considered as grouped entities and reduced randomly. I didn’t know how else to achieve it so I used the Group component.

I flatten the tree structure when using the Random Reduce component, and is now unable to return the data in to its original data structure.

I have attached a minimized file for your consideration. - gh-help-groupUngroup.gh (12.3 KB)

As an example, my target data structure is something like this:
{0;B} has 4 branches
{1;B} has 6 branches
{2;B} has 8 branches
{3;B} has 4 branches
{4;B} has 1 branch

From what remains after Random Reduce, how can I return what used to belong to the A-level branch back to that branch as a B-level branch?

I have tried Unflatten and Match Tree components.
Unflatten failed because Tree to modify has less data than the Guide Tree.
Match Tree just leaves nothing changed.

Thank you in advance!

Hello!
Hope this can help you.


Abelreply-groupUngroup.gh (14.5 KB)

Thank you! It works wonders.