atcoder#AGC016F. [AGC016F] Games on DAG

[AGC016F] Games on DAG

Score : 16001600 points

Problem Statement

There is a directed graph GG with NN vertices and MM edges. The vertices are numbered 11 through NN, and the edges are numbered 11 through MM. Edge ii is directed from xix_i to yiy_i. Here, xi<yix_i < y_i holds. Also, there are no multiple edges in GG.

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

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

  • Select an edge ii such that there is a piece placed on vertex xix_i, and move the piece to vertex yiy_i (if there are two pieces on vertex xix_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 2M2^M different possible graphs as GG', how many lead to Alice's victory? Find the count modulo 109+710^9+7.

Constraints

  • 2N152 \leq N \leq 15
  • 1MN(N1)/21 \leq M \leq N(N-1)/2
  • 1xi<yiN1 \leq x_i < y_i \leq N
  • All (xi, yi)(x_i,\ y_i) are distinct.

Input

Input is given from Standard Input in the following format:

NN MM

x1x_1 y1y_1

x2x_2 y2y_2

::

xMx_M yMy_M

Output

Print the number of GG' that lead to Alice's victory, modulo 109+710^9+7.

2 1
1 2
1

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

b250f23c38d0f5ec2204bd714e7c1516.png

3 3
1 2
1 3
2 3
6

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

8192fd32f894f708c5e4a60dcdea9d35.png

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