Update final step of decremental scc algorithm

This commit is contained in:
stefiosif
2022-06-29 17:58:52 +03:00
parent d199b7de17
commit 6b1edfa164

View File

@@ -19,6 +19,9 @@ public:
// //
void init(); void init();
//
void findSCC();
// //
bool query(const T& u, const T& v); bool query(const T& u, const T& v);
@@ -41,6 +44,11 @@ private:
template<typename T> template<typename T>
void DecrementalSCC<T>::init() { void DecrementalSCC<T>::init() {
findSCC();
}
template<typename T>
void DecrementalSCC<T>::findSCC() {
auto SCCs = Tarjan<T>(G).findSCC(); auto SCCs = Tarjan<T>(G).findSCC();
for (auto& C : SCCs) { for (auto& C : SCCs) {
@@ -73,16 +81,21 @@ void DecrementalSCC<T>::remove(const T& u, const T& v) {
// If edge e(u, v) is not contained in In(w) and Out(w), do nothing // If edge e(u, v) is not contained in In(w) and Out(w), do nothing
if (!SPT[w].first.vertices.contains(w) && if (!SPT[w].first.vertices.contains(w) &&
!SPT[w].second.vertices.contains(w)) !SPT[w].second.vertices.contains(w)){
connection[w].adjMatrix[u].erase(v);
G.adjMatrix[u].erase(v);
return; return;
}
// Update In(w) and Out(w) // Update In(w) and Out(w)
connection[w].adjMatrix[u].erase(v);
G.adjMatrix[u].erase(v);
auto inTree = BFS<T>(connection[w]).run(w); auto inTree = BFS<T>(connection[w]).run(w);
SPT[w] = std::make_pair(inTree, inTree.reverse()); SPT[w] = std::make_pair(inTree, inTree.reverse());
// If a SCC is broken, compute all SCCs again
if (!SPT[w].second.vertices.contains(u) || if (!SPT[w].second.vertices.contains(u) ||
!SPT[w].first.vertices.contains(v)) { !SPT[w].first.vertices.contains(v)) {
// TODO: Decompose C into C1, C2, ... Ck auto SCCs = Tarjan<T>(G).findSCC();
} }
} }