How Many Shortest Routes
Count the distinct shortest (fewest-hop) routes from node 1 to node N, modulo 109+7 (0 if unreachable).
Input: the first line has N and M; each of the next M lines has an edge u v (1-based).
Output: the number of shortest routes mod 109+7.
Constraints:
- 2 ≤ N ≤ 104
- 0 ≤ M ≤ 2×104
Sample Tests
Input 1
4 4 1 2 1 3 2 4 3 4
Output 1
2
Input 2
2 0
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.