Submission #1341396

#TimeUsernameProblemLanguageResultExecution timeMemory
1341396dead0neAmusement Park (CEOI19_amusementpark)C++20
100 / 100
817 ms6588 KiB
#include <bits/stdc++.h>
#define int long long
#define ii pair<int, int>
#define st first
#define nd second
#define vi vector<int>
#define pb push_back
#define spc << " " <<
#define MX 300005
#define MOD 998244353
#define inf 1e15
using namespace std;

int dp[1<<18], popcnt[1<<18], ind[1<<18];
int add(int x, int y){
    if(x+y>=MOD) return x+y-MOD;
    return x+y;
}

int subt(int x, int y){
    if(x-y<0) return x-y+MOD;
    return x-y;
}

int mult(int x, int y){
    return (x*y)%MOD;
}

void solve(){
    int n,m; cin >> n >> m;
    int edg[n]{};
    for(int i=1; i<=m; i++){
        int a,b; cin >> a >> b; a--; b--;
        edg[a]|=(1<<b);
        edg[b]|=(1<<a);
    }
    popcnt[0]=0;
    dp[0]=ind[0]=1;
    for(int i=1; i<(1<<n); i++){
        int k=(i&-i);
        popcnt[i]=popcnt[i^k]+1;
        ind[i]=0;
        //cerr << "wow" spc i spc k spc (i^k) spc ind[i^k] spc edg[__lg(k)] << endl;
        if(ind[i^k]==1 && (edg[__lg(k)]&(i^k))==0) ind[i]=1;
    }
    for(int mask=1; mask<(1<<n); mask++){
        dp[mask]=0;
        for(int i=mask; i>0; i=(i-1)&mask){
            int sub=i^mask;
            if(!ind[i]) continue;
            if(popcnt[i]&1){ //tek, poz
                dp[mask]=add(dp[mask], dp[sub]);
            }
            else{ //cift, neg
                dp[mask]=subt(dp[mask], dp[sub]);
            }
        }
    }
    cout << mult(mult(m, dp[(1<<n)-1]), 499122177) << endl;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    #ifdef Local
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
    #endif
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...