Fix TC to update correctly, and move all to-hook children on the stack
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include "algorithm/decremental_reachability.h"
|
||||
#include "graph/breadth_first_tree.h"
|
||||
|
||||
#include <stack>
|
||||
|
||||
using namespace graph;
|
||||
|
||||
namespace algo {
|
||||
@@ -61,6 +63,7 @@ bool Italiano<T>::query(const T& u, const T& v) {
|
||||
|
||||
template<typename T>
|
||||
void Italiano<T>::remove(const T& u, const T& v) {
|
||||
//TRYCATCH if (!this->G.adjMatrix[u].contains(v)) return;
|
||||
std::map<T, std::stack<T>> H;
|
||||
|
||||
for (const auto& w : this->G.vertices()) {
|
||||
@@ -72,35 +75,30 @@ void Italiano<T>::remove(const T& u, const T& v) {
|
||||
for (const auto& c : E[v].out)
|
||||
H[w].push(c);
|
||||
}
|
||||
RT[w].adjMatrix[u].erase(v);
|
||||
}
|
||||
}
|
||||
|
||||
E[u].out.erase(v);
|
||||
E[v].inc.erase(u);
|
||||
this->G.remove(u, v);
|
||||
|
||||
for (const auto& z : this->G.vertices()) {
|
||||
RT[z].adjMatrix[u].erase(v);
|
||||
while (H[z].size() > 0) {
|
||||
auto& h = H[z].top();
|
||||
const auto& h = H[z].top();
|
||||
bool found = false;
|
||||
|
||||
for (const auto& i : E[h].inc) {
|
||||
if (RT[z].contains(z, i)) {
|
||||
RT[z].adjMatrix[i].insert(h);
|
||||
//
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//
|
||||
H[z].pop();
|
||||
//
|
||||
if (!found) {
|
||||
TC[u][v] = false;
|
||||
TC[z][h] = false;
|
||||
for (const auto& o : E[h].out) {
|
||||
if (RT[z].contains(z, o)) {
|
||||
H[z].push(o);
|
||||
}
|
||||
H[z].push(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ template<typename T>
|
||||
void King<T>::remove(const T& u, const T& v) {
|
||||
this->G.remove(u, v);
|
||||
for (const auto& w : this->G.vertices()) {
|
||||
In[w].remove(u, v);
|
||||
In[w].remove(v, u);
|
||||
Out[w].remove(u, v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,11 @@ TEST_SUITE("Decremental Reachability Test") {
|
||||
|
||||
CHECK_EQ(italiano.query(1, 9), true);
|
||||
CHECK_EQ(italiano.query(1, 6), false);
|
||||
|
||||
italiano.remove(1, 2);
|
||||
|
||||
CHECK_EQ(italiano.query(1, 5), true);
|
||||
CHECK_EQ(italiano.query(1, 2), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,11 @@ TEST_SUITE("Dynamic Reachability Test") {
|
||||
|
||||
CHECK_EQ(king.query(1, 9), true);
|
||||
CHECK_EQ(king.query(1, 6), false);
|
||||
|
||||
king.remove(1, 2);
|
||||
|
||||
CHECK_EQ(king.query(1, 5), true);
|
||||
CHECK_EQ(king.query(1, 2), false);
|
||||
}
|
||||
|
||||
SUBCASE("King::insert") {
|
||||
|
||||
Reference in New Issue
Block a user