#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int B = 1000;
const int N = 1e5 + 5;
using T = pair<int, int>;
bool in[N];
bool blocked[N];
vector<int> rg[N];
vector<T> furthest[N]; //desceding on second
vector<T> merge(vector<T> x, vector<T> y) {
vector<T> ret;
int i = 0, j = 0;
int n = (int) x.size(), m = (int) y.size();
while ((int) ret.size() < B && (i < n || j < m)) {
if (i == n || (j < m && x[i].second <= y[j].second)) {
if (!in[y[j].first]) {
in[y[j].first] = 1;
ret.push_back(y[j]);
ret.back().second++;
}
j++;
} else {
if (!in[x[i].first]) {
in[x[i].first] = 1;
ret.push_back(x[i]);
}
i++;
}
}
for (int k = 0; k < (int) ret.size(); ++k) {
in[ret[k].first] = 0;
}
return ret;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
rg[v].push_back(u);
}
//for (int i = 1; i <= n; ++i) {
//for (int j : rg[i]) {
//furthest[i] = merge(furthest[i], furthest[j]);
//}
//furthest[i].emplace_back(i, 0);
//}
auto run_dp = [&](int v) {
vector<int> max_cost(n + 1, -1);
for (int i = 1; i <= n; ++i) {
if (!blocked[i]) {
max_cost[i] = 0;
}
for (int j : rg[i]) {
if (max_cost[j] != -1) {
max_cost[i] = max(max_cost[i], max_cost[j] + 1);
}
}
}
return max_cost[v];
};
while (q--) {
int v, b;
cin >> v >> b;
vector<int> qv(b);
for (int i = 0; i < b; ++i) {
cin >> qv[i];
blocked[qv[i]] = true;
}
if (false) {
for (auto [u, d] : furthest[v]) {
if (!blocked[u]) {
cout << d << '\n';
break;
}
}
} else {
cout << run_dp(v) << '\n';
}
for (int i = 0; i < b; ++i) {
blocked[qv[i]] = false;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
5108 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
1 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4964 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
5108 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
1 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4964 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
21 ms |
6292 KB |
Output is correct |
21 |
Correct |
22 ms |
6224 KB |
Output is correct |
22 |
Correct |
24 ms |
6200 KB |
Output is correct |
23 |
Correct |
24 ms |
6236 KB |
Output is correct |
24 |
Correct |
41 ms |
8532 KB |
Output is correct |
25 |
Correct |
38 ms |
8588 KB |
Output is correct |
26 |
Correct |
52 ms |
8504 KB |
Output is correct |
27 |
Correct |
36 ms |
11608 KB |
Output is correct |
28 |
Correct |
38 ms |
11604 KB |
Output is correct |
29 |
Correct |
39 ms |
11400 KB |
Output is correct |
30 |
Correct |
48 ms |
11596 KB |
Output is correct |
31 |
Correct |
42 ms |
11596 KB |
Output is correct |
32 |
Correct |
36 ms |
11348 KB |
Output is correct |
33 |
Correct |
50 ms |
11108 KB |
Output is correct |
34 |
Correct |
44 ms |
10924 KB |
Output is correct |
35 |
Correct |
41 ms |
11092 KB |
Output is correct |
36 |
Correct |
42 ms |
11200 KB |
Output is correct |
37 |
Correct |
38 ms |
11080 KB |
Output is correct |
38 |
Correct |
49 ms |
11092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
5108 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
1 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4964 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
21 ms |
6292 KB |
Output is correct |
21 |
Correct |
22 ms |
6224 KB |
Output is correct |
22 |
Correct |
24 ms |
6200 KB |
Output is correct |
23 |
Correct |
24 ms |
6236 KB |
Output is correct |
24 |
Correct |
41 ms |
8532 KB |
Output is correct |
25 |
Correct |
38 ms |
8588 KB |
Output is correct |
26 |
Correct |
52 ms |
8504 KB |
Output is correct |
27 |
Correct |
36 ms |
11608 KB |
Output is correct |
28 |
Correct |
38 ms |
11604 KB |
Output is correct |
29 |
Correct |
39 ms |
11400 KB |
Output is correct |
30 |
Correct |
48 ms |
11596 KB |
Output is correct |
31 |
Correct |
42 ms |
11596 KB |
Output is correct |
32 |
Correct |
36 ms |
11348 KB |
Output is correct |
33 |
Correct |
50 ms |
11108 KB |
Output is correct |
34 |
Correct |
44 ms |
10924 KB |
Output is correct |
35 |
Correct |
41 ms |
11092 KB |
Output is correct |
36 |
Correct |
42 ms |
11200 KB |
Output is correct |
37 |
Correct |
38 ms |
11080 KB |
Output is correct |
38 |
Correct |
49 ms |
11092 KB |
Output is correct |
39 |
Execution timed out |
2043 ms |
10828 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |