Heavy-Light Decomposition (HLD) transforms tree path queries into at most range queries on arrays. Here's the trick: decompose the tree into "heavy" chains.
A heavy child is the child with the largest subtree. All other children are "light." Following heavy edges creates chains that cover the tree.
Any path from a node to the root crosses at most light edges. Since each chain is an array segment, you can use segment trees on each chain. This sounds complex, but the idea is simple: turn a tree path into a few array ranges.