#P5293. [HNOI2019] 白兔之舞
[HNOI2019] 白兔之舞
Description
There is a directed graph with vertices. Each vertex is represented by an ordered pair , where .
This graph is not a simple graph. For any two vertices , if , then there are exactly different edges from to . If , then there is no edge.
The white rabbit will perform a dance on this graph. Initially, it is at vertex .
The white rabbit will make several jumps. In each jump, it moves from the current vertex to the next vertex along any outgoing edge. It can stop at any time (it may also stop immediately without making any jump). When it reaches a vertex whose first coordinate is , it must stop, because that vertex has no outgoing edges.
Suppose the rabbit stops after making jumps. It will record this dance as a sequence, whose -th element is the edge it took in its -th jump.
Now, given positive integers and (), for each (), find how many dances (with length ) satisfy , and the rabbit finally stops at a vertex whose second coordinate is .
Two dances are considered different if their lengths () are different, or there exists some step at which the edges they take are different.
Output the results modulo .
Input Format
The input file name is dance.in.
The first line contains five integers separated by spaces.
Then follow lines, each containing integers separated by spaces. The -th number in the -th line denotes .
Output Format
The output file name is dance.out.
Output lines in order, each containing one number: the answer modulo .
2 2 3 1 1 998244353
2 1
1 0
16
18
3 4 100 1 3 998244353
1 1 1
1 1 1
1 1 1
506551216
528858062
469849094
818871911
Hint
Sample Explanation 1
:
- Path length is , and the number of ways is .
- Path length is . There are six types of paths:
- : this path has ways;
- : this path has ways;
- : this path has ways;
- : this path has way;
- : this path has way;
- : this path has way;
So the answer is .
:
- Path length is . There are three types of paths:
- : this path has ways;
- : this path has ways;
- : this path has ways;
- Path length is . There are three types of paths:
- : this path has ways;
- : this path has ways;
- : this path has ways;
So the answer is .
Constraints
For all testdata, is a prime number, , , , , , , is a divisor of , and .
For each test point, the special constraints are as follows:
- Test points : ;
- Test point : , and the largest prime factor of is ;
- Test point : , and the largest prime factor of is ;
- Test point : ;
- Test point : ;
- Test points : the largest prime factor of is .
Translated by ChatGPT 5
京公网安备 11011102002149号