#ifndef SCC_H_ #define SCC_H_ #include "digraph.h" #include #include namespace graph { template class SCC : public Digraph { public: SCC() = default; SCC(std::map> G, T id) : Digraph(G), id(id) { normalize(); } SCC(Digraph G, T id) : id(id) { normalize(); } // Return true if v is part of this SCC bool member(const T& v); // Representative vertex of this SCC T id; bool operator==(const SCC& o) const; private: // Erase all edges that include vertices outside this SCC void normalize(); }; template void SCC::normalize() { for (const auto& u : this->vertices()) { for (const auto& v : this->adjMatrix[u]) { if (!this->adjMatrix.count(v)) { this->adjMatrix[u].erase(v); this->adjMatrix.erase(v); } } } } template bool SCC::member(const T& v) { const auto& V = this->vertices(); return std::find(V.begin(), V.end(), v) != V.end(); } template bool SCC::operator==(const SCC& o) const{ return id == o.id; } }; // namespace graph #endif