Add tests for same SCC O(1) query

This commit is contained in:
stefiosif
2022-06-29 17:33:27 +03:00
parent 8d8e6ef831
commit d199b7de17
4 changed files with 23 additions and 11 deletions

View File

@@ -36,14 +36,14 @@ private:
std::map<T, std::pair<Digraph<T>, Digraph<T>>> SPT;
// Connect each representative with its SCC
std::map<T, SCC<T>> SCCs;
std::map<T, SCC<T>> connection;
};
template<typename T>
void DecrementalSCC<T>::init() {
auto tarjan = Tarjan<T>(G).run();
auto SCCs = Tarjan<T>(G).findSCC();
for (auto& C : tarjan) {
for (auto& C : SCCs) {
const auto& w = C.representative();
// Create shortest-paths out-tree/in-tree
@@ -55,7 +55,7 @@ void DecrementalSCC<T>::init() {
A[v] = w;
// Link SCC with its representative w
SCCs[w] = C;
connection[w] = C;
}
}
@@ -77,7 +77,7 @@ void DecrementalSCC<T>::remove(const T& u, const T& v) {
return;
// Update In(w) and Out(w)
auto inTree = BFS<T>(SCCs[w]).run(w);
auto inTree = BFS<T>(connection[w]).run(w);
SPT[w] = std::make_pair(inTree, inTree.reverse());
if (!SPT[w].second.vertices.contains(u) ||