Walks of Astronomical Length
Count the directed walks of EXACTLY K edges from node 1 to node N, modulo 109+7. K is up to 1018.
Input: the first line has N, M and K; each of the next M lines has a directed edge u v (multi-edges allowed and counted).
Output: the number of length-K walks mod 109+7.
Constraints:
- 2 ≤ N ≤ 100
- 1 ≤ M ≤ 104
- 1 ≤ K ≤ 1018
Sample Tests
Input 1
3 3 2 1 2 2 3 1 3
Output 1
1
Input 2
2 1 1 1 2
Output 2
1
Discussion (opens after you solve — no spoilers before)
No comments yet.