100 #ABC211D. [ABC211D] Number of Shortest paths

[ABC211D] Number of Shortest paths

Score : 400400 points

Problem Statement

The Republic of AtCoder has NN cities numbered 11 through NN and MM roads numbered 11 through MM.

Using Road ii, you can travel from City AiA_i to BiB_i or vice versa in one hour.

How many paths are there in which you can get from City 11 to City NN as early as possible? Since the count can be enormous, print it modulo (109+7)(10^9 + 7).

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • 0M2×1050 \leq M \leq 2\times 10^5
  • 1Ai<BiN1 \leq A_i < B_i \leq N
  • The pairs (Ai,Bi)(A_i, B_i) are distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1

\vdots

AMA_M BMB_M

Output

Print the answer. If it is impossible to get from City 11 to City NN, print 00.

4 5
2 4
1 2
2 3
1 3
3 4
2

The shortest time needed to get from City 11 to City 44 is 22 hours, which is achieved by two paths: 1241 \to 2 \to 4 and 1341 \to 3 \to 4.

4 3
1 3
2 3
2 4
1

The shortest time needed to get from City 11 to City 44 is 33 hours, which is achieved by one path: 13241 \to 3 \to 2 \to 4.

2 0
0

It is impossible to get from City 11 to City 22, in which case you should print 00.

7 8
1 3
1 4
2 3
2 4
2 5
2 6
5 7
6 7
4