#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 11;
vector<int> G[MAXN];
bool vis[MAXN];
vector<int> tp;
int n, m, p;
void dfs(int v){
vis[v] = true;
for(auto i : G[v]){
if(!vis[i]) dfs(i);
}
tp.push_back(v);
}
int dp[MAXN], to[MAXN];
int32_t main(){
cin.tie(0); cout.tie(0)->sync_with_stdio(false);
cin >> n >> m >> p;
vector<int> v; v.push_back(1);
for(int i = 0; i < p; i++){
int k; cin >> k;
if(k == 1){
if(i == 0 || v.size() == 1) continue;
cout << 0 << endl; return 0;
}
if(v.size() && k == v.back()) continue;
v.push_back(k);
}
if(v.back() != n) v.push_back(n);
vector<pair<int, int>> vp, vp2;
for(int i = 0; i < m; i++){
int u, v; cin >> u >> v;
vp.push_back({u, v});
G[u].push_back(v);
}
dfs(1);
reverse(tp.begin(), tp.end());
for(int i = 0; i < tp.size(); i++){
to[tp[i]] = i + 1;
}
vector<int> d;
for(int i = 0; i < v.size(); i++){
if(to[v[i]] == 0){
cout << 0 << endl; return 0;
}
if(i != 0 && to[v[i - 1]] > to[v[i]]){
cout << 0 << endl; return 0;
}
d.push_back(to[v[i]]);
}
for(auto i : vp){
if(to[i.fi] == 0 || to[i.se] == 0) continue;
int f = to[i.fi], t = to[i.se];
if(t > *upper_bound(d.begin(), d.end(), f)) continue;
vp2.push_back({f, t});
}
sort(vp2.begin(), vp2.end());
dp[1] = 1;
for(auto i : vp2){
dp[i.se] = (dp[i.fi] + dp[i.se]) % MOD;
}
cout << dp[to[n]] << endl;
}
Compilation message
shell.cpp: In function 'int32_t main()':
shell.cpp:45:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = 0; i < tp.size(); i++){
| ~~^~~~~~~~~~~
shell.cpp:49:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23768 KB |
Output is correct |
3 |
Correct |
13 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
15 ms |
23820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23768 KB |
Output is correct |
3 |
Correct |
13 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
15 ms |
23820 KB |
Output is correct |
6 |
Correct |
15 ms |
23892 KB |
Output is correct |
7 |
Correct |
22 ms |
24988 KB |
Output is correct |
8 |
Correct |
15 ms |
24476 KB |
Output is correct |
9 |
Correct |
20 ms |
25556 KB |
Output is correct |
10 |
Correct |
22 ms |
25352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23980 KB |
Output is correct |
2 |
Correct |
80 ms |
36980 KB |
Output is correct |
3 |
Correct |
92 ms |
43560 KB |
Output is correct |
4 |
Correct |
97 ms |
49220 KB |
Output is correct |
5 |
Correct |
58 ms |
35036 KB |
Output is correct |
6 |
Correct |
218 ms |
80584 KB |
Output is correct |
7 |
Correct |
197 ms |
67800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23768 KB |
Output is correct |
3 |
Correct |
13 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
15 ms |
23820 KB |
Output is correct |
6 |
Correct |
15 ms |
23892 KB |
Output is correct |
7 |
Correct |
22 ms |
24988 KB |
Output is correct |
8 |
Correct |
15 ms |
24476 KB |
Output is correct |
9 |
Correct |
20 ms |
25556 KB |
Output is correct |
10 |
Correct |
22 ms |
25352 KB |
Output is correct |
11 |
Correct |
13 ms |
23980 KB |
Output is correct |
12 |
Correct |
80 ms |
36980 KB |
Output is correct |
13 |
Correct |
92 ms |
43560 KB |
Output is correct |
14 |
Correct |
97 ms |
49220 KB |
Output is correct |
15 |
Correct |
58 ms |
35036 KB |
Output is correct |
16 |
Correct |
218 ms |
80584 KB |
Output is correct |
17 |
Correct |
197 ms |
67800 KB |
Output is correct |
18 |
Correct |
402 ms |
88540 KB |
Output is correct |
19 |
Correct |
426 ms |
85832 KB |
Output is correct |
20 |
Correct |
288 ms |
81744 KB |
Output is correct |
21 |
Correct |
146 ms |
54964 KB |
Output is correct |
22 |
Correct |
311 ms |
84244 KB |
Output is correct |