Codeforces Global Round 15
I
Organizing a Music Festival
Codeforces
3400
原题
← H→
翻译中…

You are the organizer of the famous "Zurich Music Festival". There will be $n$ singers who will perform at the festival, identified by the integers $1$, $2$, $\dots$, $n$. You must choose in which order they are going to perform on stage.

翻译中…

You have $m$ friends and each of them has a set of favourite singers. More precisely, for each $1\le i\le m$, the $i$-th friend likes singers $s_{i,1}, \, s_{i, 2}, \, \dots, \,s_{i, q_i}$.

翻译中…

A friend of yours is happy if the singers he likes perform consecutively (in an arbitrary order). An ordering of the singers is valid if it makes all your friends happy.

翻译中…

Compute the number of valid orderings modulo $998\,244\,353$.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $m$ ($1\le n,\,m\le 100$) — the number of singers and the number of friends correspondingly.

翻译中…

The $i$-th of the next $m$ lines contains the integer $q_i$ ($1\le q_i\le n$) — the number of favorite singers of the $i$-th friend – followed by the $q_i$ integers $s_{i,1}, \, s_{i, 2}, \, \dots, \,s_{i, q_i}$ ($1\le s_{i,1} \lt s_{i,2} \lt \cdots \lt s_{i,q_i}\le n$) — the indexes of his favorite singers.

翻译中…

Output

翻译中…

Print the number of valid orderings of the singers modulo $998\,244\,353$.

翻译中…

Note

翻译中…

Explanation of the first sample: There are $3$ singers and only $1$ friend. The friend likes the two singers $1$ and $3$. Thus, the $4$ valid orderings are:

翻译中…
  • 1 3 2
  • 2 1 3
  • 2 3 1
  • 3 1 2
翻译中…

Explanation of the second sample: There are $5$ singers and $5$ friends. One can show that no ordering is valid.

翻译中…

Explanation of the third sample: There are $100$ singers and only $1$ friend. The friend likes only singer $50$, hence all the $100!$ possible orderings are valid.

翻译中…

Explanation of the fourth sample: There are $5$ singers and only $1$ friend. The friend likes all the singers, hence all the $5!=120$ possible orderings are valid.

翻译中…

样例

Input #1
3 1
2 1 3
Output #1
4
InputCopy OutputCopy
Input #2
5 5
2 1 2
2 2 3
2 3 4
2 4 5
2 1 5
Output #2
0
InputCopy OutputCopy
Input #3
100 1
1 50
Output #3
35305197
InputCopy OutputCopy
Input #4
5 1
5 1 2 3 4 5
Output #4
120
InputCopy OutputCopy
Input #5
2 5
1 2
1 2
1 2
1 1
1 1
Output #5
2
InputCopy OutputCopy
Input #6
11 4
5 4 5 7 9 11
2 2 10
2 9 11
7 1 2 3 5 8 10 11
Output #6
384
InputCopy OutputCopy
题目信息
题号
1552I
时间限制
1 s
内存限制
256 MB
标签
DFS 及类似
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。