This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/extc++.h> /** keep-include */
#include <bits/stdc++.h>
#define int long long
using namespace std;
string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
bool first = true;
string res = "[";
for (const auto &x : v) {
if (!first)
res += ", ";
first = false;
res += to_string(x);
}
res += "]";
return res;
}
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << to_string(H);
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
using ll = int;
// To use most bits rather than just the lowest ones:
struct chash { // large odd number for C
const uint64_t C = ll(4e18 * acos(0)) | 71;
ll operator()(ll x) const { return __builtin_bswap64(x * C); }
};
using hash_table = __gnu_pbds::gp_hash_table<int, int, chash>;
template <const int32_t MOD> struct ModInt {
int32_t x;
ModInt() : x(0) {}
ModInt(long long u) : x(u % MOD) {
if (x < 0)
x += MOD;
}
friend bool operator==(const ModInt &a, const ModInt &b) {
return a.x == b.x;
}
friend bool operator!=(const ModInt &a, const ModInt &b) {
return a.x != b.x;
}
friend bool operator<(const ModInt &a, const ModInt &b) { return a.x < b.x; }
friend bool operator>(const ModInt &a, const ModInt &b) { return a.x > b.x; }
friend bool operator<=(const ModInt &a, const ModInt &b) {
return a.x <= b.x;
}
friend bool operator>=(const ModInt &a, const ModInt &b) {
return a.x >= b.x;
}
static ModInt sign(long long k) {
return ((k & 1) ? ModInt(MOD - 1) : ModInt(1));
}
ModInt &operator+=(const ModInt &m) {
x += m.x;
if (x >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(const ModInt &m) {
x -= m.x;
if (x < 0LL)
x += MOD;
return *this;
}
ModInt &operator*=(const ModInt &m) {
x = (1LL * x * m.x) % MOD;
return *this;
}
friend ModInt operator-(const ModInt &a) {
ModInt res(a);
if (res.x)
res.x = MOD - res.x;
return res;
}
friend ModInt operator+(const ModInt &a, const ModInt &b) {
return ModInt(a) += ModInt(b);
}
friend ModInt operator-(const ModInt &a, const ModInt &b) {
return ModInt(a) -= ModInt(b);
}
friend ModInt operator*(const ModInt &a, const ModInt &b) {
return ModInt(a) *= ModInt(b);
}
static long long fp(long long u, long long k) {
long long res = 1LL;
while (k > 0LL) {
if (k & 1LL)
res = (res * u) % MOD;
u = (u * u) % MOD;
k /= 2LL;
}
return res;
}
static constexpr int mod() { return MOD; }
ModInt fastpow(long long k) { return ModInt(fp(x, k)); }
ModInt inv() {
assert(x);
return ModInt(fp(x, MOD - 2));
}
ModInt &operator/=(const ModInt &m) { return *this *= ModInt(m).inv(); }
friend ModInt operator/(const ModInt &a, const ModInt &b) {
return ModInt(a) *= ModInt(b).inv();
}
friend ostream &operator<<(ostream &out, const ModInt &a) {
return out << a.x;
}
friend istream &operator>>(istream &in, ModInt &a) { return in >> a.x; }
friend string to_string(ModInt u) { return to_string(u.x); }
};
// const int MOD = 1e9 + 7;
const int MOD = 998244353;
using Mint = ModInt<MOD>;
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> adj(n);
vector<int> bitAdj(n);
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
adj[u] |= 1 << v;
bitAdj[u] |= 1 << v;
bitAdj[v] |= 1 << u;
}
vector<bool> isGood(1 << n);
for (int i = 0; i < (1 << n); ++i) {
isGood[i] = true;
for (int j = 0; j < n; ++j)
if ((1 << j) & i)
isGood[i] = isGood[i] and (bitAdj[j] & i) == 0;
}
vector<Mint> dp(1 << n);
dp[0] = 1;
for (int msk = 1; msk < (1 << n); ++msk) {
for (int sub = msk; sub > 0; sub = (sub - 1) & msk)
if (isGood[sub])
dp[msk] += dp[msk ^ sub] * Mint::sign(__builtin_popcount(sub) + 1);
}
Mint sol = dp[(1 << n) - 1];
cout << sol * m / 2 << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |