1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include<bits/stdc++.h> #define ll long long #define FIO "uoj37" #define cnt(x) __builtin_popcount(x) using namespace std;
const int N=15,N2=N*N,SN=1<<N,MOD=1e9+7;
inline int add(int a,const int &b){return (a+=b)>=MOD?a-MOD:a;} inline int sub(int a,const int &b){return (a-=b)< 0?a+MOD:a;} inline int mul(const int &a,const int &b){return 1ll*a*b%MOD;} inline int& inc(int &a,const int &b){return a=add(a,b);} inline int& dec(int &a,const int &b){return a=sub(a,b);} inline int& pro(int &a,const int &b){return a=mul(a,b);} inline int qpow(int a,int b){int c=1;for(;b;b>>=1,pro(a,a))if(b&1)pro(c,a);return c;}
int n,m,up; int E[SN],f[SN],g[SN],ans[SN],bin[N2],edge[SN],id[SN],d[N][N],in[N],out[N];
int main(){ freopen(FIO".in","r",stdin); freopen(FIO".out","w",stdout);
scanf("%d%d",&n,&m); up=1<<n; for(int i=0;i<n;i++)id[1<<i]=i; bin[0]=1;for(int i=1;i<N2;i++)bin[i]=add(bin[i-1],bin[i-1]);
for(int i=1,u,v;i<=m;i++)scanf("%d%d",&u,&v),d[--u][--v]++,in[v]|=1<<u,out[u]|=1<<v;
for(int S=1;S<up;S++){ int lst=S&-S; E[S]=E[S^lst]+cnt(in[id[lst]]&(S^lst))+cnt(out[id[lst]]&(S^lst)); }
for(int S=1;S<up;S++){ int lst=S&-S; if(S==lst){ g[S]=ans[S]=1; continue; } edge[S]=0; for(int T=(S-1)&S;T;T=(T-1)&S){ int lst=(S^T)&-(S^T); edge[T]=edge[T^lst]-cnt(out[id[lst]]&(T^lst^S))+cnt(in[id[lst]]&T); }
for(int T=(S^lst)&((S^lst)-1);~T;T=T?(T-1)&(S^lst):-1){ dec(g[S],mul(ans[T^lst],g[T^lst^S])); }
for(int T=S;T;T=(T-1)&S){ inc(f[S],mul(g[T],bin[edge[T]+E[S^T]])); }
inc(g[S],ans[S]=sub(bin[E[S]],f[S])); }
printf("%d\n",ans[up-1]);
return 0; }
|