Once and are at the same depth, jump both upward simultaneously in powers of . For each from down to , check if up[a][j] != up[b][j].
If so, jump both: a = up[a][j], b = up[b][j]. After all jumps, and are directly below the LCA. The LCA is up[a][0] (or up[b][0], same thing). You try large jumps first and only make a jump if it does not overshoot the LCA.