#P14818. [ICPC 2023 Yokohama R] Chayas

[ICPC 2023 Yokohama R] Chayas

题目描述

Once upon a time, there were a number of chayas (teahouses) along one side of an east-west road in Yokohama. Although the total number of chayas is known, the information about their locations was considered to be lost totally.

Recently, a document describing the old townscapes of Yokohama has been found. The document contains a number of records on the order of the locations of chayas. Each record has information below on the order of the locations of three chayas, say aa, bb, and cc.

Chaya bb was located between chayas aa and cc. Note that there may have been other chayas between aa and bb, or between bb and cc. Also, note that chaya aa may have been located east of cc or west of cc.

We want to know how many different orders of chayas along the road are consistent with all of these records in the recently found document. Note that, as the records may have some errors, there might exist no orders consistent with the records.

输入格式

The input consists of a single test case given in the following format.

$$\begin{aligned} &n\ m \\ &a_1\ b_1\ c_1 \\ &\vdots \\ &a_m\ b_m\ c_m \end{aligned}$$

Here, nn represents the number of chayas and mm represents the number of records in the recently found document. 3n243 \le n \le 24 and 1mn×(n1)×(n2)/21 \le m \le n \times (n - 1) \times (n - 2) / 2 hold. The chayas are numbered from 1 to nn.

Each of the following mm lines represents a record. The ii-th of them contains three distinct integers aia_i, bib_i, and cic_i, each between 1 and nn, inclusive. This says that chaya bib_i was located between chayas aia_i and cic_i. No two records have the same information, that is, for any two different integers ii and jj, the triple (ai,bi,ci)(a_i, b_i, c_i) is not equal to (aj,bj,cj)(a_j, b_j, c_j) nor (cj,bj,aj)(c_j, b_j, a_j).

输出格式

Output the number of different orders of the chayas, from east to west, consistent with all of the records modulo 998244353998\,244\,353 in a line. Note that 998244353=223×7×17+1998\,244\,353 = 2^{23} \times 7 \times 17 + 1 is a prime number.

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