#ifndef SCC_H_ #define SCC_H_ #include "digraph.h" #include #include namespace graph { template class SCC : public Digraph { public: SCC() = default; SCC(std::unordered_map> G, T id) : Digraph(G), id(id) { normalize(); } SCC(Digraph G, T id) : id(id) { normalize(); } // Return true if u is part of this SCC bool contains(const T &u) const; // Representative vertex of this SCC T id{}; // std::unordered_map> neighboorList; 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->adjList[u]) { if (!this->contains(v)) { this->adjList[u].erase(v); this->adjList.erase(v); neighboorList[u].insert(v); } } } } template bool SCC::contains(const T &u) const { return this->adjList.count(u); } template bool SCC::operator==(const SCC &o) const { return id == o.id; } template struct HashSCC { std::size_t operator()(const SCC &C) const { return static_cast(C.id); } }; }; // namespace graph #endif