Files
reachability-algorithms/graph/scc.h

45 lines
909 B
C++

#ifndef SCC_H_
#define SCC_H_
#include "digraph.h"
namespace graph {
template<typename T>
class SCC : public Digraph<T> {
public:
SCC() = default;
SCC(std::map<T, std::set<T>> G, T id) : Digraph<T>(G), id(id) { normalize(); }
SCC(Digraph<T> G, T id) : id(id) { normalize(); }
T id;
bool operator==(const SCC& o) const;
private:
// For every vertex in the SCC, if there is an edge between an in-scc vertex
// and an out-scc vertex erase the edge between them and the out-scc vertex
void normalize();
};
template<typename T>
void SCC<T>::normalize() {
for (const auto& u : this->adjMatrix) {
for (const auto& v : u.second) {
if (!this->adjMatrix.count(v)) {
this->adjMatrix[u.first].erase(v);
this->adjMatrix.erase(v);
}
}
}
}
template<typename T>
bool SCC<T>::operator==(const SCC& o) const{
return id == o.id;
}
}; // namespace graph
#endif