// TLE O(4^n n^2) #include #include #include #include using vertex = size_t; using vertex_set = size_t; using edge = std::pair; namespace lib { namespace kronecker_power_transform { namespace details { template void unit_transform(UnitTransform transform, ReferenceGetter ref_getter, std::index_sequence) { transform(ref_getter(Seq)...); } } template void kronecker_power_transform(std::vector &x) { const std::size_t n = x.size(); for (std::size_t block = 1; block < n; block *= D) { for (std::size_t l = 0; l < n; l += D * block) { for (std::size_t offset = l; offset < l + block; ++offset) { const auto ref_getter = [&](std::size_t i) -> T& { return x[offset + i * block]; }; details::unit_transform(unit_transform, ref_getter, std::make_index_sequence()); } } } } } namespace subset_transform { namespace details { template void zeta_unit_transform(T &x0, T &x1) { x1 += x0; } template void mobius_unit_transform(T &x0, T &x1) { x1 -= x0; } } // namespace details template void zeta(std::vector &a) { kronecker_power_transform::kronecker_power_transform>(a); } template void mobius(std::vector &a) { kronecker_power_transform::kronecker_power_transform>(a); } } // namespace subset_transform namespace set_power_series { namespace details { template struct polynomial : std::vector { using std::vector::vector; }; template polynomial& operator+=(polynomial& p, const polynomial &q) { assert(p.size() == q.size()); for (size_t i = 0; i < p.size(); ++i) p[i] += q[i]; return p; } template polynomial& operator-=(polynomial& p, const polynomial &q) { assert(p.size() == q.size()); for (size_t i = 0; i < p.size(); ++i) p[i] -= q[i]; return p; } template polynomial& operator*=(polynomial& p, const polynomial &q) { const size_t n = p.size(); assert(n == q.size()); polynomial r(n); for (size_t i = 0; i < n; ++i) for (size_t j = 0; i + j < n; ++j) r[i + j] += p[i] * q[j]; p = std::move(r); return p; } template polynomial operator+(polynomial p, const polynomial &q) { p += q; return p; } template polynomial operator-(polynomial p, const polynomial &q) { p -= q; return p; } template polynomial operator*(polynomial p, const polynomial &q) { p *= q; return p; } template std::vector> ranked(const std::vector& a) { const int n = a.size(); std::vector fs(n, polynomial(__builtin_ctz(n) + 1, T{ 0 })); for (int i = 0; i < n; ++i) fs[i][__builtin_popcount(i)] = a[i]; return fs; } template std::vector deranked(const std::vector>& polys) { const int n = polys.size(); std::vector a(n); for (int i = 0; i < n; ++i) a[i] = polys[i][__builtin_popcount(i)]; return a; } template std::vector> ranked_zeta(const std::vector& a) { std::vector> ra = ranked(a); subset_transform::zeta(ra); return ra; } template std::vector deranked_mobius(std::vector>& ra) { subset_transform::mobius(ra); return deranked(ra); } } template std::vector subset_convolution(const std::vector& a, const std::vector& b) { const int n = a.size(); auto ra = details::ranked_zeta(a), rb = details::ranked_zeta(b); for (int i = 0; i < n; ++i) ra[i] *= rb[i]; return details::deranked_mobius(ra); } template std::vector subset_exp(const std::vector& f) { assert(f[0] == 0); const int n = __builtin_ctz(f.size()); std::vector g{1}; for (int i = 0; i < n; ++i) { std::vector p(f.begin() + (1 << i), f.begin() + (1 << (i + 1))); std::vector h = subset_convolution(std::move(p), g); std::move(h.begin(), h.end(), std::back_inserter(g)); } return g; } } template T bit_deposite(const T src, const T mask, const size_t bitwidth) { T dst = 0; size_t j = 0; for (size_t i = 0; i < bitwidth; ++i) { if ((mask >> i) & 1) dst |= ((src >> j) & 1) << i, ++j; } return dst; } } std::vector count_cycles(const size_t n, const size_t, const std::vector &edges) { std::vector adj(n, std::vector{}); for (const auto &[u, v] : edges) adj[u].push_back(v), adj[v].push_back(u); std::vector cycle_dp(1u << n, std::vector(n)); for (size_t v = 0; v < n; ++v) { cycle_dp[1u << v][v] = 1; } std::vector cycle(1u << n); for (vertex_set s = 1; s < 1u << n; ++s) { const vertex start = __builtin_ctz(s); for (vertex cur = 0; cur < n; ++cur) if (cycle_dp[s][cur]) { for (const vertex nxt : adj[cur]) { if (start == nxt) { cycle[s] += cycle_dp[s][cur]; } else if (start < nxt and not ((s >> nxt) & 1)) { const vertex_set nxt_s = s | (1u << nxt); cycle_dp[nxt_s][nxt] += cycle_dp[s][cur]; } } } } for (vertex_set s = 1; s < 1u << n; ++s) { const size_t popcnt = __builtin_popcount(s); if (popcnt == 1) cycle[s] = 1; else if (popcnt == 2) cycle[s] = 0; else cycle[s] /= 2; } return cycle; } uint64_t solve(const size_t n, const size_t m, const std::vector &edges) { // e[S] := # edges connecting vertices in S. std::vector e(1u << n); for (const auto &[u, v] : edges) { ++e[(1u << u) | (1u << v)]; } lib::subset_transform::zeta(e); using sps = std::vector; const sps cycle = count_cycles(n, m, edges); sps f{0}; for (vertex v = 0; v < n; ++v) { f.resize(1u << (v + 1)); for (vertex_set x = 1u << v; x < 1u << (v + 1); ++x) { const vertex_set full = ((1u << (v + 1)) - 1) ^ x; sps g(1u << v); for (vertex_set s = full;; --s &= full) { g[s] = f[s] * (e[s | x] - e[s] - e[x]); if (s == 0) break; } const sps exp_g = lib::set_power_series::subset_exp(g); for (vertex_set s = full;; --s &= full) { f[s | x] += cycle[x] * exp_g[s]; if (s == 0) break; } } } return lib::set_power_series::subset_exp(f).back(); } int main() { size_t n, m; std::cin >> n >> m; std::vector edges(m); for (auto &[u, v] : edges) { std::cin >> u >> v; --u, --v; } std::cout << solve(n, m, edges) << '\n'; }