#include <bits/stdc++.h>
#define NM 1000002
#define ll long long
using namespace std;
const ll MOD = 1e9+7;
vector <int> ine[NM], oute[NM];
int n, m, p;
int v[NM];
bool spv[NM];
int g[NM];
queue <int> q;
int ord[NM];
int vo[NM];
bool fs (int a, int b)
{
return ord[a] < ord[b];
}
ll dp[NM];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> p;
for(int i = 1; i <= p; i++)
{
cin >> v[i];
spv[v[i]] = 1;
}
for(int i = 1; i <= m; i++)
{
int u, v;
cin >> u >> v;
ine[v].push_back(u);
oute[u].push_back(v);
g[v]++;
}
for(int i = 1; i <= n; i++)
if(g[i] == 0)
{
ord[i] = 1;
q.push(i);
}
while(!q.empty())
{
auto f = q.front();
q.pop();
for(auto e : oute[f])
{
g[e]--;
if(g[e] == 0)
{
ord[e] = ord[f] + 1;
q.push(e);
}
}
}
for(int i = 2; i <= p; i++)
if(ord[v[i]] < ord[v[i - 1]])
{
cout << "0\n";
return 0;
}
for(int i = 1; i <= n; i++)
vo[i] = i;
sort(vo + 1, vo + n + 1, fs);
int last = 1;
dp[1] = 1;
for(int i = 2; i <= n; i++)
{
for(auto e : ine[vo[i]])
if(ord[e] >= ord[last])
dp[i] += dp[e];
if(spv[i])
last = i;
}
cout << dp[n];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
47324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
47324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
47484 KB |
Output is correct |
2 |
Correct |
116 ms |
57012 KB |
Output is correct |
3 |
Incorrect |
116 ms |
56952 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
47324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |