#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 1000002
using namespace std;
int n,m,p,x,y,d[MAX],dp[MAX],c[MAX],vf[MAX];
vector<int> v[MAX];
vector<int> mrc;
void dfs(int nod){
vf[nod] = 1;
for(int vecin: v[nod]){
if(vf[vecin] == 0){
d[vecin] = 1+dp[nod];
dfs(vecin);
}
}
}
void dfs_dp(int nod, int src, int dest){
vf[nod] = 1;
for(int vecin: v[nod]){
if(vf[vecin] == 0 && d[vecin] >= d[nod] || (vecin == dest || c[vecin] == 0)){
dp[vecin] += dp[nod];
dp[vecin] %= MOD;
dfs_dp(vecin, src, dest);
}
}
}
int nr_drum(int src, int dest){
memset(dp, 0, sizeof(dp));
memset(vf, 0, sizeof(vf));
dp[src] = 1;
dfs_dp(src, src, dest);
return dp[dest];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> p;
for(int i = 1; i <= p; i++){
cin >> x;
mrc.push_back(x);
c[x] = 1;
}
for(int i = 1; i <= m; i++){
cin >> x >> y;
v[x].push_back(y);
}
d[1] = 1;
dfs(1);
for(int i = 1; i < mrc.size(); i++){
if(d[mrc[i-1]] < d[mrc[i]]){
cout << "0\n";
return 0;
}
}
int ans = 0;
if(mrc[0] != 1){
ans += nr_drum(1, mrc[0]);
}else{
}
for(int i = 1; i < mrc.size(); i++){
ans += nr_drum(mrc[i-1], mrc[i]);
ans %= MOD;
}
if(mrc.back() != n){
ans += nr_drum(mrc.back(), n);
ans %= MOD;
}
cout << ans;
return 0;
}
Compilation message
shell.cpp: In function 'void dfs_dp(int, int, int)':
shell.cpp:22:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
22 | if(vf[vecin] == 0 && d[vecin] >= d[nod] || (vecin == dest || c[vecin] == 0)){
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
shell.cpp: In function 'int main()':
shell.cpp:54:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i = 1; i < mrc.size(); i++){
| ~~^~~~~~~~~~~~
shell.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i = 1; i < mrc.size(); i++){
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
31572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
31572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
64 ms |
31704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
31572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |