#P1842H. Tenzing and Random Real Numbers

    ID: 9924 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>bitmasksdpgraphsmathprobabilities*3000

Tenzing and Random Real Numbers

Description

There are nn uniform random real variables between 0 and 1, inclusive, which are denoted as x1,x2,,xnx_1, x_2, \ldots, x_n.

Tenzing has mm conditions. Each condition has the form of xi+xj1x_i+x_j\le 1 or xi+xj1x_i+x_j\ge 1.

Tenzing wants to know the probability that all the conditions are satisfied, modulo 998 244 353998~244~353.

Formally, let M=998 244 353M = 998~244~353. It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M}. Output the integer equal to pq1modMp \cdot q^{-1} \bmod M. In other words, output the integer xx that 0x<M0 \le x < M and xqp(modM)x \cdot q \equiv p \pmod{M}.

The first line contains two integers nn and mm (1n201\le n\le 20, 0mn2+n0\le m\le n^2+n).

Then following mm lines of input contains three integers tt, ii and jj (t{0,1}t \in \{0,1\}, 1ijn1\le i\le j\le n).

  • If t=0t=0, the condition is xi+xj1x_i+x_j\le 1.
  • If t=1t=1, the condition is xi+xj1x_i+x_j\ge 1.

It is guaranteed that all conditions are pairwise distinct.

Output the probability that all the conditions are satisfied, modulo M=998 244 353M = 998~244~353.

Input

The first line contains two integers nn and mm (1n201\le n\le 20, 0mn2+n0\le m\le n^2+n).

Then following mm lines of input contains three integers tt, ii and jj (t{0,1}t \in \{0,1\}, 1ijn1\le i\le j\le n).

  • If t=0t=0, the condition is xi+xj1x_i+x_j\le 1.
  • If t=1t=1, the condition is xi+xj1x_i+x_j\ge 1.

It is guaranteed that all conditions are pairwise distinct.

Output

Output the probability that all the conditions are satisfied, modulo M=998 244 353M = 998~244~353.

Sample Input 1

3 2
0 1 2
1 3 3

Sample Output 1

748683265

Sample Input 2

3 3
0 1 2
0 1 3
0 2 3

Sample Output 2

748683265

Sample Input 3

3 4
0 1 2
0 1 3
1 2 3
1 2 2

Sample Output 3

935854081

Sample Input 4

4 4
0 1 2
0 3 4
1 1 3
1 2 4

Sample Output 4

0

Sample Input 5

8 12
0 1 2
0 2 3
1 3 4
0 1 4
0 5 6
0 6 7
1 7 8
0 5 8
1 3 7
1 3 8
1 4 7
1 4 8

Sample Output 5

997687297

Note

In the first test case, the conditions are x1+x21x_1+x_2 \le 1 and x3+x31x_3+x_3\ge 1, and the probability that each condition is satisfied is 12\frac 12, so the probability that they are both satisfied is 1212=14\frac 12\cdot \frac 12=\frac 14, modulo 998 244 353998~244~353 is equal to 748683265748683265.

In the second test case, the answer is 14\frac 14.

In the third test case, the answer is 116\frac 1{16}.

In the fourth test case, the sum of all variables must equal 22, so the probability is 00.