# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
313793 | jhnah917 | Amusement Park (CEOI19_amusementpark) | C++14 | 2557 ms | 2844 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>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const int mod = 998244353;
int n, m;
bool g[22][22], chk[1<<18];
ll dp[1<<18];
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for(int i=0; i<m; i++){
int s, e; cin >> s >> e; s--; e--;
g[s][e] = g[e][s] = 1;
}
for(int i=0; i<(1<<n); i++){
for(int j=0; j<n; j++) if(i & (1 << j)) {
for(int k=j+1; k<n; k++) if(i & (1 << k)) {
if(g[j][k]){ chk[i] = 1; break; }
}
if(chk[i]) break;
}
}
dp[0] = 1;
for(int i=1; i<(1<<n); i++){
for(int j=i; j; j=(i&(j-1))) if(!chk[j]) {
if(__builtin_popcount(j) & 1) dp[i] += dp[i^j];
else dp[i] = dp[i] -= dp[i^j];
if(dp[i] < 0) dp[i] += mod;
if(dp[i] >= mod) dp[i] %= mod;
}
}
cout << dp[(1<<n)-1] * m % mod * (mod/2+1) % mod;
}
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... |