From f1261bb7cd35840b9b5937a6260308f3839c6f3e Mon Sep 17 00:00:00 2001 From: Yidi Date: Fri, 22 Mar 2024 12:16:34 +0100 Subject: minor (mostly spacing) changes --- graph/virtualTree.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'graph/virtualTree.cpp') 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 in, out; -void virtualTree(const vector& a) { // takes indices of used nodes - auto ind = a; +void virtualTree(vector ind) { // indices of used nodes sort(all(ind), [&](int x, int y) {return in[x] < in[y];}); - for (int i=0; i& a) { // takes indices of used nodes int n = ind.size(); vector> tree(n); - stack st{{0}}; + vector st = {0}; for (int i=1; 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 } -- cgit v1.2.3