summaryrefslogtreecommitdiff
path: root/graph/lca.cpp
diff options
context:
space:
mode:
authormzuenni <michi.zuendorf@gmail.com>2022-06-27 17:19:28 +0200
committermzuenni <michi.zuendorf@gmail.com>2022-06-27 17:19:28 +0200
commit5ab8a5088b729a9953b8dff1b2a985dc8fb2098b (patch)
treeed40d6936c0e9eee40ba62751cbf99ecddbaddc2 /graph/lca.cpp
parentadabbad9c51cf7cd3874bfde8eac1fbcf84fec10 (diff)
updated tcr
Diffstat (limited to 'graph/lca.cpp')
-rw-r--r--graph/lca.cpp28
1 files changed, 0 insertions, 28 deletions
diff --git a/graph/lca.cpp b/graph/lca.cpp
deleted file mode 100644
index d6548e9..0000000
--- a/graph/lca.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-struct LCA {
- vector<int> depth, visited, first;
- int idx;
- SparseTable st;
-
- void init(vector<vector<int>> &g, int root) { // Laufzeit: O(|V|)
- depth.assign(2 * g.size(), 0);
- visited.assign(2 * g.size(), -1);
- first.assign(g.size(), 2 * g.size());
- idx = 0;
- visit(g, root, 0);
- st.init(&depth);
- }
-
- void visit(vector<vector<int>> &g, int v, int d) {
- visited[idx] = v, depth[idx] = d, first[v] = min(idx, first[v]), idx++;
-
- for (int w : g[v]) {
- if (first[w] == 2 * (int)g.size()) {
- visit(g, w, d + 1);
- visited[idx] = v, depth[idx] = d, idx++;
- }}}
-
- int getLCA(int a, int b) { // Laufzeit: O(1)
- if (first[a] > first[b]) swap(a, b);
- return visited[st.queryIdempotent(first[a], first[b])];
- }
-};