Chayas
시간 제한8초메모리 제한1024 MB
b가 a와 c 사이에 있다는 m개의 조건을 모두 만족하는 chaya 순열의 개수를 998244353으로 나눈 나머지로 구한다.
문제
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.
Here, represents the number of chayas and represents the number of records in the recently found document. and hold. The chayas are numbered from to .
Each of the following lines represents a record. The -th of them contains three distinct integers , , and , each between 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.
힌트
For Sample Input 1, four orders, , , , and , are consistent with the records.
For Sample Input 2, there are no consistent orders.