MCPcopy Create free account
hub / github.com/ShahjalalShohag/code-library / lca

Function lca

Graph Theory/Cactus Graph.cpp:54–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52 }
53}
54int lca(int u, int v) {
55 if (dep[u] < dep[v]) swap(u, v);
56 for (int k = LG; k >= 0; k--) if (dep[par[u][k]] >= dep[v]) u = par[u][k];
57 if (u == v) return u;
58 for (int k = LG; k >= 0; k--) if (par[u][k] != par[v][k]) u = par[u][k], v = par[v][k];
59 return par[u][0];
60}
61
62
63int dp[N], up[N], done[N];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected