Lowest common ancestor
Lowest common ancestor
What is LCA?
Let a rooted tree be given.
The lowest common ancestor of two vertices and is the deepest vertex that is an ancestor of both and .
Simply put: if you go from and up to the root, then the LCA is the first vertex where their paths intersect.
What we need in advance
We assume that:
- We already know how to quickly find the -th ancestor of a vertex (using binary lifting).