#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47452 KB |
Output is correct |
2 |
Incorrect |
22 ms |
55384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47452 KB |
Output is correct |
2 |
Incorrect |
22 ms |
55384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47452 KB |
Output is correct |
2 |
Correct |
70 ms |
56984 KB |
Output is correct |
3 |
Correct |
72 ms |
57016 KB |
Output is correct |
4 |
Incorrect |
77 ms |
56972 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47452 KB |
Output is correct |
2 |
Incorrect |
22 ms |
55384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |