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/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 20
#define MAXS 18
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define smin(a, x) (a)=(min((a), (x)))
ll dp[303030];
int ban[MAX];
int mul[MAX];
const int mod = 998244353;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M;
cin >> N >> M;
int i, j, a, b;
for (i = 1; i <= M; i++) {
cin >> a >> b;
ban[--a] |= 1 << --b;
ban[b] |= 1 << a;
}
int K = 1 << N;
dp[0] = 1;
for (j = 0; j < K; j++) {
int c = 0;
for (int k = 0; k < N; k++) if ((j & (1 << k)) && (ban[k] & j)) c = 1;
if (c) continue;
mul[j] = -1;
for (int k = 0; k < N; k++) if (j & (1 << k)) mul[j] *= -1;
}
for (i = 0; i < K; i++) { for (j = i; j; (--j) &= i) { dp[i] += dp[i ^ j] * (ll)mul[j], dp[i] %= mod; } }
if (dp[K - 1] < 0) dp[K - 1] += mod;
dp[K - 1] *= M;
dp[K - 1] %= mod;
if (dp[K - 1] % 2) dp[K - 1] += mod;
dp[K - 1] /= 2;
cout << dp[K - 1] << ln;
}
# | 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... |