제출 #1134211

#제출 시각아이디문제언어결과실행 시간메모리
1134211bpptidpShell (info1cup18_shell)C++20
55 / 100
863 ms25412 KiB
#include<bits/stdc++.h> using namespace std; #define int int64_t #define pb push_back const int N=1.5e3+2,mod=1e9+7; vector<int>g[N],rg[N]; int tin[N],tout[N]; int memo[N],vrx[N]; int n,m,p,ti; int get(int u,int v){ if(u==v)return memo[v]=1; if(memo[v]!=-1)return memo[v]; int sm=0; for(int j:rg[v]) sm=(sm+get(u,j))%mod; return memo[v]=sm; } void dfs(int u){ tin[u]=++ti; for(int v:g[u])if(!tin[v])dfs(v); tout[u]=++ti; } bool iznad(int a,int b){ return tin[a]<=tin[b]&&tout[a]>=tout[b]; } bool ff(){ dfs(1); bool ok=1; for(int i=1;i<p;++i) ok&=iznad(vrx[i-1],vrx[i]); return ok; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>m>>p; for(int i=1;i<=p;++i) cin>>vrx[i]; for(int i=0,u,v;i<m;++i){ cin>>u>>v; g[u].pb(v); rg[v].pb(u); } vrx[0]=1; vrx[p+1]=n; p+=2; if(n>1000){ cout<<ff(); return 0; } int ans=1; for(int i=1;i<p;++i){ fill(memo,memo+N,-1); ans=(ans*get(vrx[i-1],vrx[i]))%mod; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...