MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / lca

Function lca

Trees/LCA.cpp:31–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31int lca(int u, int v)
32{
33 if (is_ancestor(u, v))
34 return u;
35 if (is_ancestor(v, u))
36 return v;
37 for (int i = l; i >= 0; --i) {
38 if (!is_ancestor(up[u][i], v))
39 u = up[u][i];
40 }
41 return up[u][0];
42}
43
44void preprocess(int root) {
45 tin.resize(n);

Callers 2

lcaMethod · 0.85
solveFunction · 0.85

Calls 1

is_ancestorFunction · 0.85

Tested by

no test coverage detected