Lowest common ancestor
The lowest common ancestor, or LCA, of vertices and is their common ancestor with the greatest depth. A vertex is considered its own ancestor.
Build the Euler tour
During DFS, record each vertex when entering it. After returning from a child, record the parent again.
This sequence is called an Euler tour.
For every vertex , store:
- : its depth, with .