1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
| #include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 7, mod = 1e9 + 7;
struct Node {
int to, nxt;
} tr[M * 2];
int idx, head[M];
int cnt[M];
ll num[M];
bool st[M];
void add(int u, int v) {
tr[idx] = {v, head[u]};
head[u] = idx++;
}
void bfs() {
queue<int> q;
q.push(1);
num[1] = 1;
st[1] = true;
while (q.size()) {
int now = q.front();
q.pop();
for (int i = head[now]; ~i; i = tr[i].nxt) {
int j = tr[i].to;
if (st[j] && cnt[j] == cnt[now] + 1) {
num[j] = (num[j] + num[now]) % mod;
} else if (!st[j]) {
cnt[j] = cnt[now] + 1;
num[j] = num[now];
st[j] = true;
q.push(j);
}
}
}
}
int main() {
memset(head, -1, sizeof head);
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
add(x, y), add(y, x);
}
bfs();
printf("%lld\n", num[n]);
return 0;
}
|