Submission #498040

#TimeUsernameProblemLanguageResultExecution timeMemory
498040andrei_boacaAmusement Park (CEOI19_amusementpark)C++14
100 / 100
1057 ms2832 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; typedef long long ll; typedef pair<int,int> pii; const ll mod=998244353,inv2=499122177; int n,m,bits[25],lg,cmask[25]; int dp[(1<<18)+5]; int B[25]; bool isthere[1000006]; ll gethash(ll x, ll y) { ll rez=(x<<18); rez+=y; return rez; } bool good[(1<<18)+5],edge[25][25]; int bit[(1<<18)+5]; int main() { cin>>n>>m; for(int i=1;i<=m;i++) { int a,b; cin>>a>>b; cmask[a]+=(1<<(b-1)); cmask[b]+=(1<<(a-1)); a--; b--; edge[a][b]=edge[b][a]=1; } for(int mask=0;mask<(1<<n);mask++) { for(int a=0;a<n;a++) if((mask>>a)&1) for(int b=0;b<n;b++) if((mask>>b)&1) good[mask]|=edge[a][b]; good[mask]= !good[mask]; if(mask==0) bit[mask]=-1; else { int lsb=(mask&(-mask)); bit[mask]=bit[mask^lsb]*(-1); } } for(int mask=0;mask<(1<<n);mask++) { if(good[mask]) { dp[mask]=1; continue; } for(int submask=mask;submask>0;submask=(submask-1)&mask) if(good[submask]&&submask!=mask) dp[mask]=(dp[mask]+bit[submask]*dp[mask^submask]+mod)%mod; } ll ans=dp[(1<<n)-1]; ans=(ans*m)%mod; ans=(ans*inv2)%mod; cout<<ans; return 0; }
#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...