#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cassert>
#include <string>
#include <cstring>
#include <bitset>
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};
const int N = 1500 + 5;
const int M = 1500 + 5;
const int MOD = 1e9 + 7;
int n, m, k, streak [N];
int lvl [N], dp [N][M];
vvi g (N);
void add (int &a, int b) {
a += b;
while (a >= MOD) a -= MOD;
}
void build (int node, int depth = 0) {
lvl[node] = depth;
GO (to, g[node]) {
build (to, depth + 1);
}
}
int solve (int node, int match) {
if (node == n - 1) return (match == k);
if (lvl[node] > lvl[streak[match]]) return 0;
if (~dp[node][match]) return dp[node][match];
dp[node][match] = 0;
int target = (match < k ? streak[match] : -1);
GO (to, g[node]) add (dp[node][match], solve (to, match + (to == target)));
return dp[node][match];
}
int main () {
scanf ("%d %d %d", &n, &m, &k);
memset (dp, -1, sizeof(dp));
F0R (i, k) {
scanf ("%d", &streak[i]);
--streak[i];
}
F0R (i, m) {
int st, et;
scanf ("%d %d", &st, &et);
--st; --et;
g[st].eb(et);
}
build (0);
printf("%d\n", solve (0, streak[0] == 0 ? 1 : 0));
return 0;
}
Compilation message
shell.cpp: In function 'int main()':
shell.cpp:78:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d %d", &n, &m, &k);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
shell.cpp:81:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d", &streak[i]);
~~~~~~^~~~~~~~~~~~~~~~~~
shell.cpp:86:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &st, &et);
~~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9216 KB |
Output is correct |
2 |
Incorrect |
17 ms |
9216 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9216 KB |
Output is correct |
2 |
Incorrect |
17 ms |
9216 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1099 ms |
9088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9216 KB |
Output is correct |
2 |
Incorrect |
17 ms |
9216 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |