Guest User

Untitled

a guest
Feb 24th, 2021
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. class brute_force {
  2. public:
  3.     explicit brute_force(graph g) : _g(std::move(g)) {};
  4.     void fill_set();
  5.  
  6. private:
  7.     graph _g;
  8.     std::unordered_set<graph, graph_hash> all_subgraphs;
  9.  
  10.     void impl_fill(graph const& g);
  11. };
  12. void brute_force::impl_fill(graph const& g) {
  13.     if(all_subgraphs.find(g) == all_subgraphs.end()) {
  14.         if(g.is_reachable(_s, _d)) {
  15.             all_subgraphs.insert(g);
  16.             for(size_t i = 0; i < g.num_edges(); ++i) {
  17.                 graph tmp = g.erase_edge(i);
  18.                 impl_fill(tmp);
  19.             }
  20.         }
  21.     }
  22. }
  23.  
  24. void brute_force::fill_set() {
  25.     impl_fill(_g);
  26. }
  27.  
  28. class graph {
  29. public:
  30.     using byte = unsigned char;
  31.     using edge_type = std::vector<std::pair<byte, byte>>;
  32.  
  33.     graph() = default;
  34.     graph(graph const& other) = default;
  35.     graph(edge_type edges, byte n) : edges(std::move(edges)), n(n) {};
  36.  
  37.     bool is_reachable(byte s, byte d) const;
  38.     graph erase_edge(size_t const& i) const;
  39.  
  40.     friend bool operator==(graph const& lhs, graph const& rhs);
  41.  
  42.     size_t num_edges() const;
  43. private:
  44.     edge_type edges; //список ребёр
  45.     byte n = 0; //число вершин
  46. };
  47.  
  48. graph graph::erase_edge(size_t const& i) const {
  49.     graph res(*this);
  50.     res.edges.erase(edges.begin()+i);
  51.     return res;
  52. }
  53. size_t graph::num_edges() const {
  54.     return edges.size();
  55. }
Advertisement
Add Comment
Please, Sign In to add comment