#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long p,n,m,c[1000010],st[1000010],nr,mua[1000010],x,y;
vector<vector<long long>>a;
struct posibilitati{long long nr,lc;}pr[1000010];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m>>p;
for(long long i=1;i<=p;++i)
{
cin>>c[i];
pr[c[i]].lc=c[i];
}
if(c[1]!=1)
c[0]=1;
else
nr=1;
if(c[p]!=n)
c[++p]=n;
a.resize(n+5);
for(long long i=1;i<=m;++i)
{
cin>>x>>y;
a[x].push_back(y);
++mua[y];
}
for(long long i=1;i<=n;++i)
if(mua[i]==0)
st[++st[0]]=i;
for(long long i=1;i<=n;++i)
{
for(auto x:a[st[i]])
{
--mua[x];
if(mua[x]==0)
st[++st[0]]=x;
}
}
pr[1].nr=1;
pr[1].lc=1;
for(long long i=1;i<=n;++i)
{
long long q=st[i];
if(pr[q].lc==c[nr+1])
++nr;
if(pr[q].lc==c[nr])
{
for(auto x:a[q])
{
if(pr[x].lc==pr[q].lc||pr[x].lc==c[nr+1])
{
pr[x].nr+=pr[q].nr;
if(pr[x].nr>MOD)
pr[x].nr-=MOD;
}
else if(pr[x].lc!=x)
pr[x]=pr[q];
}
}
}
cout<<pr[n].nr;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
848 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
5 ms |
1116 KB |
Output is correct |
10 |
Correct |
5 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
68 ms |
9976 KB |
Output is correct |
3 |
Correct |
65 ms |
9896 KB |
Output is correct |
4 |
Correct |
62 ms |
9928 KB |
Output is correct |
5 |
Correct |
40 ms |
6696 KB |
Output is correct |
6 |
Correct |
160 ms |
22980 KB |
Output is correct |
7 |
Correct |
146 ms |
22916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
848 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
5 ms |
1116 KB |
Output is correct |
10 |
Correct |
5 ms |
848 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
68 ms |
9976 KB |
Output is correct |
13 |
Correct |
65 ms |
9896 KB |
Output is correct |
14 |
Correct |
62 ms |
9928 KB |
Output is correct |
15 |
Correct |
40 ms |
6696 KB |
Output is correct |
16 |
Correct |
160 ms |
22980 KB |
Output is correct |
17 |
Correct |
146 ms |
22916 KB |
Output is correct |
18 |
Correct |
254 ms |
33876 KB |
Output is correct |
19 |
Correct |
249 ms |
31796 KB |
Output is correct |
20 |
Correct |
225 ms |
30664 KB |
Output is correct |
21 |
Correct |
79 ms |
11656 KB |
Output is correct |
22 |
Correct |
239 ms |
32568 KB |
Output is correct |