forked from Jonathan-Uy/CSES-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame Routes.cpp
More file actions
37 lines (31 loc) · 697 Bytes
/
Game Routes.cpp
File metadata and controls
37 lines (31 loc) · 697 Bytes
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 1e5+1;
const ll MOD = 1e9+7;
int N, M, a, b, cnt, in[maxN];
ll dp[maxN];
vector<int> G[maxN];
queue<int> Q;
int main(){
scanf("%d %d", &N, &M);
for(int i = 0; i < M; i++){
scanf("%d %d", &a, &b);
G[a].push_back(b);
in[b]++;
}
for(int i = 1; i <= N; i++)
if(in[i] == 0)
Q.push(i);
dp[1] = 1;
while(!Q.empty()){
int u = Q.front(); Q.pop();
for(int v : G[u]){
dp[v] = (dp[v] + dp[u]) % MOD;
in[v]--;
if(in[v] == 0)
Q.push(v);
}
}
printf("%lld\n", dp[N]);
}