#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 , , and .
Chaya was located between chayas and . Note that there may have been other chayas between and , or between and . Also, note that chaya may have been located east of or west of .
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, represents the number of chayas and represents the number of records in the recently found document. and hold. The chayas are numbered from 1 to .
Each of the following lines represents a record. The -th of them contains three distinct integers , , and , each between 1 and , inclusive. This says that chaya was located between chayas and . No two records have the same information, that is, for any two different integers and , the triple is not equal to nor .
输出格式
Output the number of different orders of the chayas, from east to west, consistent with all of the records modulo in a line. Note that 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