#abc211d. D - Number of Shortest paths

D - Number of Shortest paths

Score : 400400 points

问题描述

在AtCoder共和国,有编号为11NNNN个城市和编号为11MMMM条道路。

通过第ii号道路,可以在一小时内从城市AiA_i到达城市BiB_i或反之亦然。

请问从城市11尽可能早地到达城市NN有多少种路径?
由于计数结果可能非常巨大,请输出模(109+7)(10^9 + 7)后的结果。

以上为通义千问 qwen-max 翻译,仅供参考。

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.

Sample Input 1

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

Sample Output 1

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.

Sample Input 2

4 3
1 3
2 3
2 4

Sample Output 2

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.

Sample Input 3

2 0

Sample Output 3

0

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

Sample Input 4

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

Sample Output 4

4

update @ 2024/3/10 09:25:56