atcoder#DPR. Walk
Walk
Score : points
Problem Statement
There is a simple directed graph with vertices, numbered .
For each and (), you are given an integer that represents whether there is a directed edge from Vertex to . If , there is a directed edge from Vertex to ; if , there is not.
Find the number of different directed paths of length in , modulo . We will also count a path that traverses the same edge multiple times.
Constraints
- All values in input are integers.
- is or .
Input
Input is given from Standard Input in the following format:
Output
Print the number of different directed paths of length in , modulo .
4 2
0 1 0 0
0 0 1 1
0 0 0 1
1 0 0 0
6
is drawn in the figure below:
There are six directed paths of length :
- → →
- → →
- → →
- → →
- → →
- → →
3 3
0 1 0
1 0 1
0 0 0
3
is drawn in the figure below:
There are three directed paths of length :
- → → →
- → → →
- → → →
6 2
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 0 0 0 1
0 0 0 0 0 0
1
is drawn in the figure below:
There is one directed path of length :
- → →
1 1
0
0
10 1000000000000000000
0 0 1 1 0 0 0 1 1 0
0 0 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 1 0 1
1 1 1 0 1 1 0 1 1 0
0 1 1 1 0 1 0 1 1 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 0 0 1 0 1
1 0 0 0 1 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
1 0 1 1 1 0 1 1 1 0
957538352
Be sure to print the count modulo .