Tarjan's offline LCA algorithm.