krist7599555

dq1_dense - Dense Graph

Oct 14th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #ifndef __DENSE_GRAPH_H__
  2. #define __DENSE_GRAPH_H__
  3. #include <set>
  4. #include <map>
  5.  
  6. class DenseGraph{
  7. public:
  8.     DenseGraph(): DenseGraph(3) {}
  9.     DenseGraph(int n_in): n(n_in) {}
  10.     DenseGraph(const DenseGraph& G): n(G.n), edge(G.edge) {}
  11.     void AddEdge(int a, int b) {
  12.         edge[a].insert(b);
  13.     }
  14.     void RemoveEdge(int a, int b) {
  15.         edge[a].erase(b);
  16.     }
  17.     bool DoesEdgeExist(int a, int b) const {
  18.             return edge.count(a) ? edge.at(a).count(b) : false;
  19.     }
  20.     DenseGraph Transpose() const {
  21.         DenseGraph result(n);
  22.         for (auto p : edge) {
  23.         for (auto v : p.second) {
  24.           result.AddEdge(v, p.first);
  25.         }}
  26.         return result;
  27.     }
  28. protected:
  29.     size_t n;
  30.     std::map<int, std::set<int>> edge;
  31. };
  32. #endif // __DENSE_GRAPH_H__
Add Comment
Please, Sign In to add comment