Transform a Flat Entity-Relation Array into a Nested Object Tree
Given a flat array of entity-relation tuples (e.g., [{parent: 'A', child: 'B'}, {parent: 'B', child: 'C'}]), write a function that reconstructs the hierarchical parent-child tree as a nested object. Handle cycles, multiple children per parent, and root detection (nodes with no parent). This pattern is common in org-chart builders, category trees, menu systems, and any UI that renders hierarchical data from flat API responses.