luogu#P4982. 规划
规划
Background
After a long period of hard work, finally got into his dream school.
Problem Description
As a foodie, did not go to register on his first day after enrollment. Instead, he went to the cafeteria to check the dishes. However, for various reasons, there are very few dishes in the cafeteria this semester, and the cafeteria has made a menu for several days. Therefore, during this semester, the dishes provided each day in the future will cycle in turn according to the menu.
After hearing this, was of course devastated, but he still hopes that what he eats every day will not be too repetitive. So decides that it is enough as long as the dishes he eats do not overlap with the previous day. But as a foodie, also does not want to go hungry, so he must eat at least one dish every day.
wants to know how many legal planning schemes he has, but he finds there are simply too many. So he asks you for help and hopes you can write a program to compute it for him.
Input Format
The first line contains three positive integers , meaning this semester has days, there are kinds of dishes in total, and the school has made a -day menu (all dishes are numbered from to , and it is guaranteed that ).
The next lines describe the menu. In each line, the first number is , meaning the school prepared dishes on that day, followed by numbers indicating which dishes they are (it is guaranteed that does not exceed , and these numbers are all distinct).
Output Format
Output the number of legal schemes. Since the answer may be too large, you only need to output the value modulo .
3 3 2
2 1 3
2 2 3
11
10 7 3
5 1 2 3 4 5
3 1 3 7
4 1 2 6 7
730285459
Hint
Sample Explanation:
Scheme : On day , eat dishes ; on day , eat dish ; on day , eat dishes .
Scheme : On day , eat dishes ; on day , eat dish ; on day , eat dish .
Scheme : On day , eat dishes ; on day , eat dish ; on day , eat dish .
Scheme : On day , eat dish ; on day , eat dish ; on day , eat dishes .
Scheme : On day , eat dish ; on day , eat dish ; on day , eat dish .
Scheme : On day , eat dish ; on day , eat dish ; on day , eat dish .
Scheme : On day , eat dish ; on day , eat dishes ; on day , eat dish .
Scheme : On day , eat dish ; on day , eat dish ; on day , eat dish .
Scheme : On day , eat dish ; on day , eat dish ; on day , eat dishes .
Scheme : On day , eat dish ; on day , eat dish ; on day , eat dish .
Scheme : On day , eat dish ; on day , eat dish ; on day , eat dish .
Constraints:
-
For of the testdata, .
-
For of the testdata, .
-
For another of the testdata, .
-
For of the testdata, .
-
For of the testdata, .
Translated by ChatGPT 5