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;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()
const int MAXN = 18;
const int MOD = 998244353;
int adj[1 << MAXN], popcnt[1 << MAXN], pie[1 << MAXN], nodeid[1 << MAXN], f[1 << MAXN];
bool indepset[1 << MAXN];
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m, u, v;
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> u >> v;
u--, v--;
adj[u] |= (1ll << v);
adj[v] |= (1ll << u);
}
for(int i = 0; i < n; i++){
nodeid[1ll << i] = i;
}
for(int i = 0; i < (1ll << n); i++){
popcnt[i] = popcnt[i >> 1] + (i & 1);
pie[i] = (popcnt[i] % 2) * 2 - 1;
}
indepset[0] = true;
for(int i = 1; i < (1ll << n); i++){
if(indepset[i & (i - 1)] && ((adj[nodeid[i & -i]] & (i & (i - 1))) == 0)){ // deciding whether the subset including the nodes in the mask id DAG
indepset[i] = true;
}
}
f[0] = 1;
for(int i = 1; i < (1ll << n); i++){ // O(3^n)
for(int j = i; j; j = (j - 1) & i){
if(indepset[j]){
f[i] = (f[i] + pie[j] * f[i ^ j]) % MOD; // PIE
}
}
}
f[(1 << n) - 1] = (f[(1 << n) - 1] + MOD) % MOD;
cout << f[(1 << n) - 1] * m % MOD * ((MOD + 1) / 2) % MOD; // (MODE + 1) / 2 is the modular inverse of 2.
return 0;
}
# | 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... |