Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class brute_force {
- public:
- explicit brute_force(graph g) : _g(std::move(g)) {};
- void fill_set();
- private:
- graph _g;
- std::unordered_set<graph, graph_hash> all_subgraphs;
- void impl_fill(graph const& g);
- };
- void brute_force::impl_fill(graph const& g) {
- if(all_subgraphs.find(g) == all_subgraphs.end()) {
- if(g.is_reachable(_s, _d)) {
- all_subgraphs.insert(g);
- for(size_t i = 0; i < g.num_edges(); ++i) {
- graph tmp = g.erase_edge(i);
- impl_fill(tmp);
- }
- }
- }
- }
- void brute_force::fill_set() {
- impl_fill(_g);
- }
- class graph {
- public:
- using byte = unsigned char;
- using edge_type = std::vector<std::pair<byte, byte>>;
- graph() = default;
- graph(graph const& other) = default;
- graph(edge_type edges, byte n) : edges(std::move(edges)), n(n) {};
- bool is_reachable(byte s, byte d) const;
- graph erase_edge(size_t const& i) const;
- friend bool operator==(graph const& lhs, graph const& rhs);
- size_t num_edges() const;
- private:
- edge_type edges; //список ребёр
- byte n = 0; //число вершин
- };
- graph graph::erase_edge(size_t const& i) const {
- graph res(*this);
- res.edges.erase(edges.begin()+i);
- return res;
- }
- size_t graph::num_edges() const {
- return edges.size();
- }
Advertisement
Add Comment
Please, Sign In to add comment