@@ -33,7 +33,7 @@ def create_sparse(max_node: int, parent: list[list[int]]) -> list[list[int]]:
33
33
For example, consider a small tree where:
34
34
- Node 1 is the root (its parent is 0),
35
35
- Nodes 2 and 3 have parent 1.
36
-
36
+
37
37
We set up the parent table for only two levels (row 0 and row 1)
38
38
for max_node = 3. (Note that in practice the table has many rows.)
39
39
@@ -57,11 +57,18 @@ def lowest_common_ancestor(
57
57
) -> int :
58
58
"""
59
59
Return the lowest common ancestor (LCA) of nodes u and v in a tree.
60
+ <<<<<<< HEAD
60
61
61
62
The lists ``level`` and ``parent`` must be precomputed. ``level[i]`` is the depth
62
63
of node i, and ``parent`` is a sparse table where parent[0][i] is the direct parent
63
64
of node i.
64
65
66
+ =======
67
+
68
+ The lists `level` and `parent` must be precomputed. `level[i]` is the depth of node i,
69
+ and `parent` is a sparse table where parent[0][i] is the direct parent of node i.
70
+
71
+ >>>>>>> 097e9c6149e80f095be1b3dbef1c04ff94a7325a
65
72
>>> # Consider a simple tree:
66
73
>>> # 1
67
74
>>> # / \\
@@ -136,6 +143,7 @@ def main() -> None:
136
143
sparse table and compute several lowest common ancestors.
137
144
138
145
The sample tree used is:
146
+ <<<<<<< HEAD
139
147
140
148
1
141
149
/ | \
@@ -145,6 +153,17 @@ def main() -> None:
145
153
/ \\ | / \\
146
154
9 10 11 12 13
147
155
156
+ =======
157
+
158
+ 1
159
+ / | \
160
+ 2 3 4
161
+ / / \\ \\
162
+ 5 6 7 8
163
+ / \\ | / \\
164
+ 9 10 11 12 13
165
+
166
+ >>>>>>> 097e9c6149e80f095be1b3dbef1c04ff94a7325a
148
167
The expected lowest common ancestors are:
149
168
- LCA(1, 3) --> 1
150
169
- LCA(5, 6) --> 1
@@ -154,7 +173,7 @@ def main() -> None:
154
173
- LCA(8, 8) --> 8
155
174
156
175
To test main() without it printing to the console, we capture the output.
157
-
176
+
158
177
>>> import sys
159
178
>>> from io import StringIO
160
179
>>> backup = sys.stdout
0 commit comments