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>
using namespace std;
#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
const int N = 18, MOD = 998244353;
int adj[N];
map<int, int> dp[1 << N];
int add(int a, int b) {
return a + b < MOD ? a + b : a + b - MOD;
}
int mul(int a, int b) {
return a * (ll) b % MOD;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
--a, --b;
adj[a] |= (1 << b);
adj[b] |= (1 << a);
}
dp[0][(1 << n) - 1] = 1;
for (int a = 0; a < (1 << n); ++a) {
for (auto [b, cnt] : dp[a]) {
for (int i = 0; i < n; ++i) {
if (b & 1 << i) {
int newb = b & (1 << n) - (1 << (i + 1));
newb = newb | (adj[i] | a) ^ a;
dp[a ^ 1 << i][newb] = add(dp[a ^ 1 << i][newb], cnt);
}
}
}
}
cout << mul(dp[(1 << n) - 1][0], mul(m, (MOD + 1) / 2));
return 0;
}
Compilation message (stderr)
amusementpark.cpp: In function 'int main()':
amusementpark.cpp:46:45: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
46 | int newb = b & (1 << n) - (1 << (i + 1));
| ~~~~~~~~~^~~~~~~~~~~~~~~~
amusementpark.cpp:47:48: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
47 | newb = newb | (adj[i] | a) ^ a;
| ~~~~~~~~~~~~~^~~
# | 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... |