Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- int n;
- int m;
- int dp[100005];
- vector<int>graph[100005];
- int rec(int node){
- int result=0;
- if(node==n){
- return 1;
- }
- if(dp[node]!=-1){
- return dp[node];
- }
- int MOD = 1e9 + 7;
- for(int i=0; i<graph[node].size(); i++){
- int sosed=graph[node][i];
- result+=rec(sosed);
- result %= MOD;
- }
- return dp[node]=result;
- }
- int main()
- {
- 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);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement