Add tests for same SCC O(1) query
This commit is contained in:
@@ -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) ||
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
Tarjan(Digraph<T> G) : G(G) {}
|
||||
|
||||
//
|
||||
std::vector<SCC<T>> run();
|
||||
std::vector<SCC<T>> findSCC();
|
||||
|
||||
//
|
||||
void strongConnect(const T& v);
|
||||
@@ -68,7 +68,7 @@ void Tarjan<T>::strongConnect(const T& v) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::vector<SCC<T>> Tarjan<T>::run() {
|
||||
std::vector<SCC<T>> Tarjan<T>::findSCC() {
|
||||
for (const auto& v : G.vertices) {
|
||||
if (p[v].index == -1) {
|
||||
strongConnect(v);
|
||||
|
||||
Reference in New Issue
Block a user