Mistake : Forgetting to process the heavy child first during decomposition. This breaks the chain structure because nodes in the same chain will not get consecutive positions. Mistake : Including the LCA twice when merging the two paths from and .
The final segment should include the LCA only once. Mistake : Using the wrong segment tree range when querying chains. The order is pos[head[v]] <= pos[v] for all , with the head having the smaller position.