MCPcopy Create free account
hub / github.com/anupam-kumar-krishnan/Competitive_Programming / lca

Function lca

All Algorithms/Graph Algorithm/LCA.cpp:18–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16 }
17}
18int lca(int u, int v) {
19 if (dep[u] < dep[v]) swap(u, v);
20 for (int k = LG; k >= 0; k--) if (dep[par[u][k]] >= dep[v]) u = par[u][k];
21 if (u == v) return u;
22 for (int k = LG; k >= 0; k--) if (par[u][k] != par[v][k]) u = par[u][k], v = par[v][k];
23 return par[u][0];
24}
25int kth(int u, int k) {
26 assert(k >= 0);
27 for (int i = 0; i <= LG; i++) if (k & (1 << i)) u = par[u][i];

Callers 2

distFunction · 0.85
goFunction · 0.85

Calls 1

swapFunction · 0.50

Tested by

no test coverage detected