summaryrefslogtreecommitdiff
path: root/graph/virtualTree.cpp
diff options
context:
space:
mode:
authorMZuenni <michi.zuendorf@gmail.com>2024-06-28 13:47:18 +0200
committerMZuenni <michi.zuendorf@gmail.com>2024-06-28 13:47:18 +0200
commit65d2ac37862ce9d1de208a05099c281863e66256 (patch)
treed1fe1ece8790e8e8b2a8bcd3895f82477b3a0e2b /graph/virtualTree.cpp
parenta3c9198048cf465a3c01827b3667edfc99d8031c (diff)
parent366ff0a4ba0c94f5cdc2cbd4e2c991ad0b544522 (diff)
merge
Diffstat (limited to 'graph/virtualTree.cpp')
-rw-r--r--graph/virtualTree.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/graph/virtualTree.cpp b/graph/virtualTree.cpp
new file mode 100644
index 0000000..2fcea80
--- /dev/null
+++ b/graph/virtualTree.cpp
@@ -0,0 +1,22 @@
+// needs dfs in- and out- time and lca function
+vector<int> in, out;
+
+void virtualTree(vector<int> ind) { // indices of used nodes
+ sort(all(ind), [&](int x, int y) {return in[x] < in[y];});
+ for (int i=0; i<sz(a)-1; i++) {
+ ind.push_back(lca(ind[i], ind[i+1]));
+ }
+ sort(all(ind), [&](int x, int y) {return in[x] < in[y];});
+ ind.erase(unique(all(ind)), ind.end());
+
+ int n = ind.size();
+ vector<vector<int>> tree(n);
+ vector<int> st = {0};
+ for (int i=1; i<n; i++) {
+ while (in[ind[i]] >= out[ind[st.back()]]) st.pop_back();
+ tree[st.back()].push_back(i);
+ st.push(i);
+ }
+ // virtual directed tree with n nodes, original indices in ind
+ // weights can be calculated, e.g. with binary lifting
+}