# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
985994 | duckindog | Amusement Park (CEOI19_amusementpark) | C++17 | 1361 ms | 2128 KiB |
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;
const int N = 153 + 10,
M = 998'244'353,
MASK = 1 << 18;
int n, m;
vector<int> ad[N];
int a[N], b[N];
bool chk[MASK];
int f[MASK];
void add(auto& x, const auto& y) {
x += y;
if (x >= M) x -= M;
}
int powder(int a, int b) {
int ret = 1;
while (b) {
if (b & 1) ret = 1ll * ret * a % M;
a = 1ll * a * a % M;
b >>= 1;
}
return ret;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
cin >> a[i] >> b[i];
ad[a[i]].push_back(b[i]);
ad[b[i]].push_back(a[i]);
}
for (int mask = 1; mask < (1 << n); ++mask) {
chk[mask] = true;
for (int i = 1; i <= m; ++i)
chk[mask] &= !(mask >> a[i] - 1 & 1) || !(mask >> b[i] - 1 & 1);
}
f[0] = 1;
for (int mask = 1; mask < (1 << n); ++mask) {
for (int sMask = mask; sMask; sMask = (sMask - 1) & mask) {
if (!chk[sMask]) continue;
if (__builtin_popcountll(sMask) & 1) add(f[mask], f[mask ^ sMask]);
else add(f[mask], M - f[mask ^ sMask]);
}
}
cout << 1ll * f[(1 << n) - 1] * m % M * powder(2, M - 2) % M << "\n";
}
Compilation message (stderr)
# | 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... |