Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <cstring>
- #include <set>
- #include <map>
- using namespace std;
- int n, m;
- vector<int> graph[200005];
- int dp[200005];
- int rec(int node) {
- if(node == n) {
- return 1;
- }
- if(dp[node] != -1) {
- return dp[node];
- }
- int result = 0, MOD = 1e9 + 7;
- for(int i = 0; i < (int) graph[node].size(); i++) {
- int neigh = graph[node][i];
- result += rec(neigh);
- result %= MOD;
- }
- return dp[node] = result;
- }
- int main(int argc, const char* argv[]) {
- cin >> n >> m;
- for(int i = 0; i < m; i++) {
- int a, b;
- cin >> a >> b;
- graph[a].push_back(b);
- }
- memset(dp, -1, sizeof dp);
- cout << rec(1) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement