This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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.push_back(n),p++;
}else{
p++;
c[1]=1;
c[2]=chk;
for(int i=3; i<=p; i++) cin>>c[i];
if(c[p]!=n) c.push_back(n),p++;
}
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |