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 ar array
typedef int64_t ll;
//~ #define int ll
const int mod = 119 << 23 | 1;
const int N = 18;
unordered_map<int, int> dp[1 << N];
int is[N];
int bp(int a, int b){
int c = 1;
while(b){
if(b & 1) c = c * 1ll * a % mod;
a = a * 1ll * a % mod, b >>= 1;
} return c;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin>>n>>m;
for(int i=0;i<m;i++){
int a, b; cin>>a>>b;
--a, --b;
is[a] |= (1 << b);
is[b] |= (1 << a);
}
dp[0][0] = 1;
for(int mask=0;mask < (1 << n);mask++){
for(int j=0;j<n;j++){
if(mask >> j & 1) continue;
int on_j = mask | (1 << j);
for(int m2=on_j;m2 < (1 << n); m2++, m2 |= on_j){
int bad = m2 ^ on_j;
if(!dp[mask].count(bad)) continue;
int edge_out = ((1 << n) - 1) ^ (is[j] ^ (is[j] & mask));
int bad2 = ((bad | ((1 << j) - 1)) ^ (mask & ((1 << j) - 1))) & edge_out;
dp[on_j][bad2] = (dp[on_j][bad2] + dp[mask][bad]) % mod;
}
}
}
int res = dp[(1 << n) - 1][0];
//~ cout<<res<<"\n";
cout<<res * 1ll * bp(2, mod - 2) % mod * m % mod<<"\n";
}
# | 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... |