diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-04-01 19:59:01 +0200 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-04-01 19:59:01 +0200 |
| commit | 33343f96d94f2d7f12567b1c227e4e2399c8bd1b (patch) | |
| tree | 16b5ef80ee4605ce88410911fbb6beb6dfc1d7b2 /graph/virtualTree.cpp | |
| parent | 4fc39dcd54243609febc1ce4c8a1470b3d31fd47 (diff) | |
| parent | 98aa28427350e72cb9abe4071c0c6b6870b7e6cc (diff) | |
merge mzuenni changes
Diffstat (limited to 'graph/virtualTree.cpp')
| -rw-r--r-- | graph/virtualTree.cpp | 13 |
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 } |
