#P10990. [2015杭电多校]Too Simple
[2015杭电多校]Too Simple
Too Simple
Problem Description
Rhason Cheung had a simple problem, and asked Teacher Mai for help. But Teacher Mai thought this problem was too simple, sometimes naive. So she ask you for help. Teacher Mai has functions $f_1,f_2,\cdots,f_m:\{1,2,\cdots,n\}\to\{1,2,\cdots,n\}$(that means for all ). But Rhason only knows some of these functions, and others are unknown. She wants to know how many different function series there are that for every ,. Two function series and are considered different if and only if there exist ,.
Input
For each test case, the first lines contains two numbers . The following are lines. In -th line, there is one number or space-separated numbers. If there is only one number , the function is unknown. Otherwise the -th number in the -th line means .
Output
For each test case print the answer modulo .
Sample Input
3 3
1 2 3
-1
3 2 1
Sample Output
1
Hint
The order in the function series is determined. What she can do is to assign the values to the unknown functions.
Author
xudyh
Source
2015 Multi-University Training Contest 9