Graph Theory37 sections · 1633 units
Open in Course

Path Queries II - Lessons

(What you learned)

You decomposed a tree into heavy chains, reducing path queries to O(log⁡n)O(\log n) segment tree queries. The heavy edge rule guarantees the O(log⁡n)O(\log n) chain crossing property by halving subtree size with each light edge. You combined HLD with a segment tree to handle updates in O(log⁡n)O(\log n) and queries in O(log⁡2n)O(\log^2 n) per operation.

This technique generalizes to any path operation: sum, min, max, GCD, XOR. Next problem: handling edge-weighted trees with the same structure.