Data Structures & AlgorithmsVery hardICPC regional · tree data structures

Problem: Which statement about heavy-light decomposition for path queries on a tree is correct?

  1. A. Any root-to-node path crosses O(log n) light edges, so a path query costs O(log^2 n) with a segment tree per chain
  2. B. Every path query costs O(1) after the decomposition
  3. C. Path queries need O(n) time because light edges must be scanned one by one
  4. D. It works only for paths of length at most 2

Correct answer: A. Any root-to-node path crosses O(log n) light edges, so a path query costs O(log^2 n) with a segment tree per chain

Each light edge at least halves subtree size, so a path crosses O(log n) chains, and each chain query costs O(log n) in the segment tree.

More Coding Interview Problems questions

Exams that ask this topic