Submission #988136

#TimeUsernameProblemLanguageResultExecution timeMemory
988136Kevin_JaoShell (info1cup18_shell)C++17
100 / 100
259 ms76372 KiB
#include<iostream> #include<map> #include<set> #include<cmath> #include<queue> #include<deque> #include<stack> #include<string> #include<math.h> #include<vector> #include<stdio.h> #include<utility> #include<iomanip> #include<string.h> #include<limits.h> #include<algorithm> #include<functional> #include<unordered_map> using namespace std; #define MOD 1000000007 #define int long long #define ss second #define ff first #define endl '\n' int t; int n,m,p; const int mxN=1e6+5; vector<bool> vis(mxN); vector<int> v[mxN],c(mxN),cnt(mxN),ans(mxN); void dfs(int a){ vis[a]=1; if(a==t){ cnt[a]=1; ans[a]=1; }else{ for(auto node: v[a]){ if(!vis[node]) dfs(node); if(cnt[node]>cnt[a]){ cnt[a]=cnt[node]; ans[a]=ans[node]; }else if(cnt[node]==cnt[a]){ ans[a]=(ans[a]+ans[node])%MOD; } } } if(a==c[p-cnt[a]+1]) cnt[a]++; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m>>p; int chk; cin>>chk; if(chk==1){ c[1]=1; for(int i=2; i<=p; i++) cin>>c[i]; if(c[p]!=n) c[++p]=n; }else{ p++; c[1]=1; c[2]=chk; for(int i=3; i<=p; i++) cin>>c[i]; if(c[p]!=n) c[++p]=n; } t=c[p]; for(int i=1; i<=m; i++){ int a,b; cin>>a>>b; v[a].push_back(b); } dfs(c[1]); cout<<ans[c[1]]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...