diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2023-08-29 01:07:11 +0200 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2023-08-29 01:07:11 +0200 |
| commit | bc7a54f2a10ff3bb76cf4920be53000264bad279 (patch) | |
| tree | b19e51925e5aa067bf0aba866b9447ba31973adf /graph/LCA_sparse.cpp | |
| parent | 4905811a7c635f28827984a999aedacd910f4dc3 (diff) | |
consistency
Diffstat (limited to 'graph/LCA_sparse.cpp')
| -rw-r--r-- | graph/LCA_sparse.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/graph/LCA_sparse.cpp b/graph/LCA_sparse.cpp index a56dafa..2a864c0 100644 --- a/graph/LCA_sparse.cpp +++ b/graph/LCA_sparse.cpp @@ -4,29 +4,29 @@ struct LCA { int idx; SparseTable st; //sparse table von oben - void init(vector<vector<int>>& g, int root) { - depth.assign(2 * sz(g), 0); - visited.assign(2 * sz(g), -1); - first.assign(sz(g), 2 * sz(g)); + void init(vector<vector<int>>& adj, int root) { + depth.assign(2 * sz(adj), 0); + visited.assign(2 * sz(adj), -1); + first.assign(sz(adj), 2 * sz(adj)); idx = 0; - visit(g, root); + dfs(adj, root); st.init(&depth); } - void visit(vector<vector<int>>& g, int v, ll d=0, int p=-1) { + void dfs(vector<vector<int>>& adj, int v, ll d=0, int p=-1) { visited[idx] = v, depth[idx] = d; first[v] = min(idx, first[v]), idx++; - for (int w : g[v]) { - if (first[w] == 2 * sz(g)) { - visit(g, w, d + 1, v); + for (int u : adj[v]) { + if (first[u] == 2 * sz(adj)) { + dfs(adj, u, d + 1, v); visited[idx] = v, depth[idx] = d, idx++; }}} - int getLCA(int a, int b) { - if (first[a] > first[b]) swap(a, b); - return visited[st.queryIdempotent(first[a], first[b] + 1)]; + int getLCA(int u, int v) { + if (first[u] > first[v]) swap(u, v); + return visited[st.queryIdempotent(first[u], first[v] + 1)]; } - ll getDepth(int a) {return depth[first[a]];} + ll getDepth(int v) {return depth[first[v]];} }; |
