Technique
Heavy-Light Decomposition
Split the tree into heavy chains so any path crosses O(log n) chains, then answer path queries with a segment tree over chain order.
0%
mastery
0/2 solved
0/2 solved
Recognise it
The signal
path sum/max queries with point or range updates
1Brute force
Walk the path node by node.
2The observation
Linear path walks: each light edge at least halves the subtree size.
3Why it works
Positions of each heavy chain are contiguous in the base array.
Reach for it when
- +subtree and path queries together
Not when
- ×no updates (binary lifting with min/max tables suffices)
- ×tree changes over time
Practice
0/2 solved
- TouristsCodeforces3200
- Path Queries IICSESHard
Pitfalls
Misconceptions
- !edge values must be stored on the child node
Go deeper1 combinations · resources
Combinations
Heavy-Light Decomposition+Segment Tree / Fenwick (BIT)
max/sum on path u-v with point updates
- Heavy-Light Decomposition:
- maps each path to O(log n) contiguous ranges
- Segment Tree / Fenwick (BIT):
- range max/sum per chain