#ifndef DIGRAPH_H_ #define DIGRAPH_H_ #include "graph.h" #include "algorithm/breadth_first_search.h" namespace graph { template class Digraph : public Graph { public: Digraph() = default; explicit Digraph(std::unordered_map> G); // Return true if there is a path from u to v bool contains(const T& u, const T& v); // Add edge e(u,v) void insert(const T& u, const T& v); // Remove edge e(u,v) void remove(const T& u, const T& v); // Reverse graph directions auto reverse(); }; template Digraph::Digraph(std::unordered_map> G) { this->adjList = G; } template bool Digraph::contains(const T& u, const T& v) { return algo::BreadthFirstSearch(this->adjList).query(u, v); } template void Digraph::insert(const T& u, const T& v) { this->adjList[u].insert(v); this->adjList[v]; } template void Digraph::remove(const T& u, const T& v) { this->adjList[u].erase(v); } template auto Digraph::reverse() { std::unordered_map> revMatrix; for (const auto& u : this->vertices()) { for (const auto& v : this->adjList[u]) { revMatrix[v].insert(u); } } return revMatrix; } } // namespace graph #endif