Build the summing matrix S for the hierarchy.
S is an m × n matrix where:
Row order: topological (parents before children), depth-first. Column order: bottom nodes sorted by id for determinism.
if the hierarchy is not a valid tree (cycles, multiple roots, orphans, or no bottom level).
Build the summing matrix S for the hierarchy.
S is an m × n matrix where:
Row order: topological (parents before children), depth-first. Column order: bottom nodes sorted by id for determinism.