Submission #363231

#TimeUsernameProblemLanguageResultExecution timeMemory
363231Tenis0206Shell (info1cup18_shell)C++11
100 / 100
592 ms81512 KiB
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9+7; int n,m,p,spc[1000005]; long long lvl[1000005],cnt[1000005]; bool sel[1000005]; vector<int> G[1000005],IN[1000005],d; void dfs(int x) { sel[x]=true; for(auto it : G[x]) { if(!sel[it]) { dfs(it); } } d.push_back(x); } void topsort() { dfs(1); reverse(d.begin(),d.end()); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m>>p; for(int i=1;i<=p;i++) { int x; cin>>x; spc[x]=i; } for(int i=1;i<=m;i++) { int x,y; cin>>x>>y; G[x].push_back(y); IN[y].push_back(x); } topsort(); memset(sel,false,sizeof(sel)); cnt[1]=1; for(auto nod : d) { sel[nod]=true; int tofind = 0; if(spc[nod]) { lvl[nod]=spc[nod]; } for(auto it : IN[nod]) { if(!spc[nod] && lvl[it]>lvl[nod]) { lvl[nod]=lvl[it]; cnt[nod]=0; } if(!spc[nod] && lvl[it]==lvl[nod]) { cnt[nod]+=cnt[it]; cnt[nod]%=Mod; } if(spc[nod] && lvl[it]==lvl[nod]-1) { cnt[nod]+=cnt[it]; cnt[nod]%=Mod; } } } if(lvl[n]==p) { cout<<cnt[n]%Mod<<'\n'; return 0; } cout<<0<<'\n'; return 0; }

Compilation message (stderr)

shell.cpp: In function 'int main()':
shell.cpp:50:13: warning: unused variable 'tofind' [-Wunused-variable]
   50 |         int tofind = 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...