Create getter method for the SCC collection
This commit is contained in:
@@ -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<T, SCC<T>> getSCCs() { return C; }
|
||||
|
||||
void setGraph(Digraph<T> G);
|
||||
private:
|
||||
// Array used to answer strong connectivity queries in O(1) time
|
||||
@@ -37,8 +39,8 @@ private:
|
||||
std::map<T, SCC<T>> C;
|
||||
|
||||
// Maintain in-out bfs trees
|
||||
std::map<T, BreadthFirstTree<T>> inTree;
|
||||
std::map<T, BreadthFirstTree<T>> outTree;
|
||||
std::map<T, BreadthFirstTree<T>> In;
|
||||
std::map<T, BreadthFirstTree<T>> Out;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -53,11 +55,11 @@ void RodittyZwick<T>::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<T>(SCC, w);
|
||||
inTree[w] = BreadthFirstTree<T>(SCC.reverse(), w);
|
||||
Out[w] = BreadthFirstTree<T>(SCC, w);
|
||||
In[w] = BreadthFirstTree<T>(SCC.reverse(), w);
|
||||
|
||||
C[w] = SCC;
|
||||
}
|
||||
@@ -78,16 +80,16 @@ void RodittyZwick<T>::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<T>(C[w], w);
|
||||
inTree[w] = BreadthFirstTree<T>(C[w].reverse(), w);
|
||||
Out[w] = BreadthFirstTree<T>(C[w], w);
|
||||
In[w] = BreadthFirstTree<T>(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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user