Update italiano::remove
This commit is contained in:
@@ -38,7 +38,6 @@ private:
|
||||
std::map<T, Edges> E;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
void Italiano<T>::init() {
|
||||
for (const auto& u : std::views::keys(G.adjMatrix)) {
|
||||
@@ -62,21 +61,45 @@ bool Italiano<T>::query(const T& u, const T& v) {
|
||||
|
||||
template<typename T>
|
||||
void Italiano<T>::remove(const T& u, const T& v) {
|
||||
std::map<T, std::set<T>> R;
|
||||
std::map<T, std::forward_list<T>> R;
|
||||
for (const auto& w : std::views::keys(G.adjMatrix)) {
|
||||
if (RT[w].contains(u, v)) {
|
||||
R[w].insert(v);
|
||||
if (RT[w].contains(u, v) &&
|
||||
std::distance(E[w].inc.begin(), E[w].inc.end()) > 1) {
|
||||
if (E[v].inc.front() == u) {
|
||||
E[v].inc.pop_front();
|
||||
R[w].push_front(E[v].inc.front());
|
||||
E[v].inc.push_front(u);
|
||||
} else {
|
||||
R[w].push_front(E[v].inc.front());
|
||||
}
|
||||
}
|
||||
E[u].inc.remove(v);
|
||||
E[u].out.remove(u);
|
||||
G.remove(u, v);
|
||||
}
|
||||
E[u].inc.remove(v);
|
||||
E[u].out.remove(u);
|
||||
G.remove(u, v);
|
||||
|
||||
//for (const auto& w : std::views::keys(G.adjMatrix)) {
|
||||
// while (R[w].size() > 0) {
|
||||
// auto pop = R[w].
|
||||
// }
|
||||
//}
|
||||
for (const auto& w : std::views::keys(G.adjMatrix)) {
|
||||
bool hooked = false;
|
||||
// R contains all vertices that need a hook-parent
|
||||
while (!R[w].empty()) {
|
||||
// z is a candidate hook-parent if it is in RT[w]
|
||||
const auto& toHook = R[w].front();
|
||||
for (const auto& z : E[toHook].inc) {
|
||||
if (RT[w].contains(u, z)) {
|
||||
R[w].remove(toHook);
|
||||
hooked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hooked) {
|
||||
TC[w][toHook] = false;
|
||||
for (const auto& z : E[toHook].out) {
|
||||
if (RT[w].contains(toHook, z))
|
||||
R[w].push_front(z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace algo
|
||||
|
||||
Reference in New Issue
Block a user