Centroid decomposition turns all-pairs path counting into single-source distance counting. You process each node times instead of checking paths for each node. The subtract step prevents double-counting paths within subtrees.
This is standard in divide-and-conquer: include everything, then subtract what you will handle recursively. You can apply this pattern to other path properties: sums, XOR, products, or any property that depends on the path as a whole.