Problem:
Score : 1600 points

Problem Statement

There is a directed graph G with N vertices and M edges.
The vertices are numbered 1 through N, and the edges are numbered 1 through M.
Edge i is directed from x_i to y_i.
Here, x_i < y_i holds.
Also, there are no multiple edges in G.

Consider selecting a subset of the set of the M edges in G, and removing these edges from G to obtain another graph G'.
There are 2^M different possible graphs as G'.

Alice and Bob play against each other in the following game played on G'.
First, place two pieces on vertices 1 and 2, one on each.
Then, starting from Alice, Alice and Bob alternately perform the following operation:

Select an edge i such that there is a piece placed on vertex x_i, and move the piece to vertex y_i (if there are two pieces on vertex x_i, only move one). The two pieces are allowed to be placed on the same vertex.

The player loses when he/she becomes unable to perform the operation.
We assume that both players play optimally.

Among the 2^M different possible graphs as G', how many lead to Alice's victory?
Find the count modulo 10^9+7.

Constraints

2 ≤ N ≤ 15

1 ≤ M ≤ N(N-1)/2

1 ≤ x_i < y_i ≤ N

All (x_i,\ y_i) are distinct.

Input

Input is given from Standard Input in the following format:

N M
x_1 y_1
x_2 y_2
:
x_M y_M

Output

Print the number of G' that lead to Alice's victory, modulo 10^9+7.

Sample Input 1

2 1
1 2

Sample Output 1

1

The figure below shows the two possible graphs as G'.
A graph marked with ○ leads to Alice's victory, and a graph marked with × leads to Bob's victory.

Sample Input 2

3 3
1 2
1 3
2 3

Sample Output 2

6

The figure below shows the eight possible graphs as G'.

Sample Input 3

4 2
1 3
2 4

Sample Output 3

2

Sample Input 4

5 10
2 4
3 4
2 5
2 3
1 2
3 5
1 3
1 5
4 5
1 4

Sample Output 4

816

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#define file "gemo"
using namespace std;
typedef long long ll;
const int mod=1000000007;
int read(){
	char c=getchar();
	int x=0;
	while(c<'0' || c>'9')
		c=getchar();
	while(c>='0' && c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x;
}
int a[15][15];
ll dp[1<<15][16],pw[2333];
int to[16][1<<15],qwq[1<<15];
int main(){
	//freopen(file".in","r",stdin);
	//freopen(file".out","w",stdout);
	int n=read(),m=read();
	pw[0]=1;
	for(int i=1;i<=m;i++)
		pw[i]=pw[i-1]*2%mod;
	for(int i=1;i<=m;i++){
		int u=read()-1,v=read()-1;
		a[u][v]=1;
	}
	for(int i=0;i<n;i++)
		for(int j=0;j<(1<<n);j++){
			if (j>>i&1)
				continue;
			for(int k=0;k<n;k++)
				if (j>>k&1)
					to[i][j]+=a[i][k];
			//fprintf(stderr,"to[%d][%d]=%d\n",i,j,to[i][j]);
		}
	for(int i=0;i<(1<<n);i++)
		for(int j=0;j<n;j++)
			if (!(i>>j&1))
				qwq[i]+=to[j][i];
	dp[0][0]=1;
	for(int i=0;i<(1<<n);i++){
		int s=(1<<n)-1-i;
		if ((i&1)!=(i>>1&1))
			continue;
		//fprintf(stderr,"i=%d\n",i);
		bool flag=true;
		for(int j=0;j<n;j++)
			if (dp[i][j])
				flag=false;
		if (flag)
			continue;
		for(int j=s;j;j=(j-1)&s){ //i->j ~to->j
			if ((j&1)!=(j>>1&1))
				continue;
			ll ans=1;
			int sm=0;
			int v=i|j;
			for(int o=0;o<n;o++)
				if (!(v>>o&1))
					ans=ans*((1<<to[o][j])-1)%mod,sm+=to[o][j];
			ans=ans*pw[qwq[j]-sm]%mod;
			if (!ans)
				continue;
			for(int o=0;o<n;o++){
				//fprintf(stderr,"dp[%d][%d]=%lld\n",i,o,dp[i][o]);
				dp[v][o+1]=(dp[v][o+1]+dp[i][o]*ans)%mod;
			}
		}
	}
	ll ans=0;
	for(int i=0;i<=n;i++)
		ans=(ans+dp[(1<<n)-1][i])%mod;
	printf("%lld",((pw[m]-ans)%mod+mod)%mod);
	//fprintf(stderr,"%.5f",(double)clock()/CLOCKS_PER_SEC);
}