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 endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
#define mp make_pair
ll mod=998244353;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=18;
ll DP[(1<<N)];
ll ile[(1<<N)];
int G[N];
int RG[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,a,b;
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>a>>b;
a--,b--;
G[a]^=(1<<b);
RG[b]^=(1<<a);
}
for(int x=1;x<(1<<n);x++)
{
bool ok=1;
for(int j=0;j<n;j++)
{
if((x&(1<<j))==0) continue;
if(((G[j]|RG[j])&x)!=0) ok=0;
}
ile[x]=ok;
}
for(int x=1;x<(1<<n);x++)
{
for(int y=x;y>0;y=(y-1)&x)
{
bool ok=1;
ll cnt=0;
for(int j=0;j<n;j++)
{
if((y&(1<<j))==0) continue;
if(((G[j]|RG[j])&(x^y))==0) ok=0;
if(((G[j]|RG[j])&y)!=0) ok=0;
cnt+=__builtin_popcount(RG[j]&(x^y));
}
if(ok)
{
DP[x]=(DP[x]+ile[x^y]*cnt+DP[x^y])%mod;
ile[x]=(ile[x]+ile[x^y])%mod;
}
}
}
cout<<DP[(1<<n)-1];
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... |