This commit is contained in:
Siddhant Jain 2025-01-13 17:02:12 -05:00
commit 419ccccf24

View File

@ -57,11 +57,18 @@ def lowest_common_ancestor(
) -> int:
"""
Return the lowest common ancestor (LCA) of nodes u and v in a tree.
<<<<<<< HEAD
The lists ``level`` and ``parent`` must be precomputed. ``level[i]`` is the depth
of node i, and ``parent`` is a sparse table where parent[0][i] is the direct parent
of node i.
=======
The lists `level` and `parent` must be precomputed. `level[i]` is the depth of node i,
and `parent` is a sparse table where parent[0][i] is the direct parent of node i.
>>>>>>> 097e9c6149e80f095be1b3dbef1c04ff94a7325a
>>> # Consider a simple tree:
>>> # 1
>>> # / \\
@ -136,6 +143,7 @@ def main() -> None:
sparse table and compute several lowest common ancestors.
The sample tree used is:
<<<<<<< HEAD
1
/ | \
@ -145,6 +153,17 @@ def main() -> None:
/ \\ | / \\
9 10 11 12 13
=======
1
/ | \
2 3 4
/ / \\ \\
5 6 7 8
/ \\ | / \\
9 10 11 12 13
>>>>>>> 097e9c6149e80f095be1b3dbef1c04ff94a7325a
The expected lowest common ancestors are:
- LCA(1, 3) --> 1
- LCA(5, 6) --> 1