summaryrefslogtreecommitdiff
path: root/graph/virtualTree.cpp
diff options
context:
space:
mode:
authorYidi <noob999noob999@gmail.com>2024-03-22 12:16:34 +0100
committerYidi <noob999noob999@gmail.com>2024-03-22 12:16:34 +0100
commitf1261bb7cd35840b9b5937a6260308f3839c6f3e (patch)
tree2042f32b7c5b4cec7255e66f32f75640ec529f11 /graph/virtualTree.cpp
parent9906aa7bbf98bee5cdb91e80f6a2311e43129c7d (diff)
minor (mostly spacing) changes
Diffstat (limited to 'graph/virtualTree.cpp')
-rw-r--r--graph/virtualTree.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/graph/virtualTree.cpp b/graph/virtualTree.cpp
index f7a3cb1..2fcea80 100644
--- a/graph/virtualTree.cpp
+++ b/graph/virtualTree.cpp
@@ -1,10 +1,8 @@
// needs dfs in- and out- time and lca function
vector<int> in, out;
-void virtualTree(const vector<int>& a) { // takes indices of used nodes
- auto ind = a;
+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]));
}
@@ -13,13 +11,12 @@ void virtualTree(const vector<int>& a) { // takes indices of used nodes
int n = ind.size();
vector<vector<int>> tree(n);
- stack<int> st{{0}};
+ vector<int> st = {0};
for (int i=1; i<n; i++) {
- while (in[ind[i]] >= out[ind[st.top()]]) st.pop();
- tree[st.top()].push_back(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 if necessary, e.g. with binary lifting
+ // weights can be calculated, e.g. with binary lifting
}