diff --git a/algorithm/roditty_zwick.h b/algorithm/roditty_zwick.h index ad3a04c..3464ac9 100644 --- a/algorithm/roditty_zwick.h +++ b/algorithm/roditty_zwick.h @@ -28,6 +28,8 @@ public: // Remove edge (u,v) and update A accordingly for fast checking query void remove(const T& u, const T& v) override; + std::map> getSCCs() { return C; } + void setGraph(Digraph G); private: // Array used to answer strong connectivity queries in O(1) time @@ -37,8 +39,8 @@ private: std::map> C; // Maintain in-out bfs trees - std::map> inTree; - std::map> outTree; + std::map> In; + std::map> Out; }; template @@ -53,11 +55,11 @@ void RodittyZwick::findSCC() { for (auto& SCC : SCCs) { const auto& w = SCC.id; - for (const auto& v : std::views::keys(SCC.adjMatrix)) + for (const auto& v : SCC.vertices()) A[v] = w; - outTree[w] = BreadthFirstTree(SCC, w); - inTree[w] = BreadthFirstTree(SCC.reverse(), w); + Out[w] = BreadthFirstTree(SCC, w); + In[w] = BreadthFirstTree(SCC.reverse(), w); C[w] = SCC; } @@ -78,16 +80,16 @@ void RodittyZwick::remove(const T& u, const T& v) { if (A[u] != A[v]) return; // If edge (u,v) is not contained in both inTree and outTree do nothing - if (!inTree[w].adjMatrix[u].contains(v) && - !outTree[w].adjMatrix[u].contains(v)) + if (!In[w].adjMatrix[u].contains(v) && + !Out[w].adjMatrix[u].contains(v)) return; // Update In(w) and Out(w) - outTree[w] = BreadthFirstTree(C[w], w); - inTree[w] = BreadthFirstTree(C[w].reverse(), w); + Out[w] = BreadthFirstTree(C[w], w); + In[w] = BreadthFirstTree(C[w].reverse(), w); // If a SCC is broken, compute all SCCs again - if (!inTree[w].adjMatrix.count(u) || !outTree[w].adjMatrix.count(v)) + if (!In[w].adjMatrix.count(u) || !Out[w].adjMatrix.count(v)) findSCC(); }