#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
const int mxN=1e5, bs=20;
int n, m, q, dp2[mxN], c[mxN];
vector<int> adj[mxN];
vector<pii> dp1[mxN];
priority_queue<pii, vector<pii>, greater<pii>> pq;
bool a[mxN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
while(m--) {
int u, v;
cin >> u >> v, --u, --v;
adj[v].push_back(u);
}
for(int i=0; i<n; ++i) {
pq.push({0, i});
for(int v : adj[i]) {
for(pii p : dp1[v]) {
pq.push({p.fi+1, p.se});
if(pq.size()>bs)
pq.pop();
}
}
while(!pq.empty()) {
dp1[i].push_back(pq.top());
pq.pop();
}
}
while(q--) {
int t, y, ans=-1;
cin >> t >> y, --t;
for(int i=0; i<y; ++i) {
cin >> c[i], --c[i];
a[c[i]]=1;
}
if(y>bs) {
memset(dp2, -1, 4*(t+1));
for(int i=0; i<=t; ++i) {
dp2[i]=a[i]?-n:0;
for(int v : adj[i])
dp2[i]=max(dp2[v]+1, dp2[i]);
}
ans=max(dp2[t], ans);
} else {
for(int i=dp1[t].size()-1; i>=0; --i) {
if(a[dp1[t][i].se])
continue;
ans=dp1[t][i].fi;
break;
}
}
for(int i=0; i<y; ++i)
a[c[i]]=0;
cout << ans << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5240 KB |
Output is correct |
3 |
Correct |
6 ms |
5240 KB |
Output is correct |
4 |
Correct |
7 ms |
5240 KB |
Output is correct |
5 |
Correct |
11 ms |
5440 KB |
Output is correct |
6 |
Correct |
10 ms |
5440 KB |
Output is correct |
7 |
Correct |
11 ms |
5440 KB |
Output is correct |
8 |
Correct |
9 ms |
5600 KB |
Output is correct |
9 |
Correct |
10 ms |
5600 KB |
Output is correct |
10 |
Correct |
10 ms |
5600 KB |
Output is correct |
11 |
Correct |
10 ms |
5608 KB |
Output is correct |
12 |
Correct |
10 ms |
5608 KB |
Output is correct |
13 |
Correct |
11 ms |
5608 KB |
Output is correct |
14 |
Correct |
9 ms |
5608 KB |
Output is correct |
15 |
Correct |
9 ms |
5608 KB |
Output is correct |
16 |
Correct |
10 ms |
5608 KB |
Output is correct |
17 |
Correct |
10 ms |
5608 KB |
Output is correct |
18 |
Correct |
9 ms |
5608 KB |
Output is correct |
19 |
Correct |
10 ms |
5608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5240 KB |
Output is correct |
3 |
Correct |
6 ms |
5240 KB |
Output is correct |
4 |
Correct |
7 ms |
5240 KB |
Output is correct |
5 |
Correct |
11 ms |
5440 KB |
Output is correct |
6 |
Correct |
10 ms |
5440 KB |
Output is correct |
7 |
Correct |
11 ms |
5440 KB |
Output is correct |
8 |
Correct |
9 ms |
5600 KB |
Output is correct |
9 |
Correct |
10 ms |
5600 KB |
Output is correct |
10 |
Correct |
10 ms |
5600 KB |
Output is correct |
11 |
Correct |
10 ms |
5608 KB |
Output is correct |
12 |
Correct |
10 ms |
5608 KB |
Output is correct |
13 |
Correct |
11 ms |
5608 KB |
Output is correct |
14 |
Correct |
9 ms |
5608 KB |
Output is correct |
15 |
Correct |
9 ms |
5608 KB |
Output is correct |
16 |
Correct |
10 ms |
5608 KB |
Output is correct |
17 |
Correct |
10 ms |
5608 KB |
Output is correct |
18 |
Correct |
9 ms |
5608 KB |
Output is correct |
19 |
Correct |
10 ms |
5608 KB |
Output is correct |
20 |
Correct |
197 ms |
6788 KB |
Output is correct |
21 |
Correct |
195 ms |
6788 KB |
Output is correct |
22 |
Correct |
197 ms |
6788 KB |
Output is correct |
23 |
Correct |
201 ms |
6788 KB |
Output is correct |
24 |
Correct |
421 ms |
30640 KB |
Output is correct |
25 |
Correct |
454 ms |
30640 KB |
Output is correct |
26 |
Correct |
390 ms |
30640 KB |
Output is correct |
27 |
Correct |
356 ms |
35636 KB |
Output is correct |
28 |
Correct |
353 ms |
35692 KB |
Output is correct |
29 |
Correct |
377 ms |
35692 KB |
Output is correct |
30 |
Correct |
353 ms |
35692 KB |
Output is correct |
31 |
Correct |
411 ms |
35692 KB |
Output is correct |
32 |
Correct |
363 ms |
35692 KB |
Output is correct |
33 |
Correct |
307 ms |
35692 KB |
Output is correct |
34 |
Correct |
363 ms |
35692 KB |
Output is correct |
35 |
Correct |
316 ms |
35692 KB |
Output is correct |
36 |
Correct |
312 ms |
35692 KB |
Output is correct |
37 |
Correct |
389 ms |
35692 KB |
Output is correct |
38 |
Correct |
342 ms |
35692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5240 KB |
Output is correct |
3 |
Correct |
6 ms |
5240 KB |
Output is correct |
4 |
Correct |
7 ms |
5240 KB |
Output is correct |
5 |
Correct |
11 ms |
5440 KB |
Output is correct |
6 |
Correct |
10 ms |
5440 KB |
Output is correct |
7 |
Correct |
11 ms |
5440 KB |
Output is correct |
8 |
Correct |
9 ms |
5600 KB |
Output is correct |
9 |
Correct |
10 ms |
5600 KB |
Output is correct |
10 |
Correct |
10 ms |
5600 KB |
Output is correct |
11 |
Correct |
10 ms |
5608 KB |
Output is correct |
12 |
Correct |
10 ms |
5608 KB |
Output is correct |
13 |
Correct |
11 ms |
5608 KB |
Output is correct |
14 |
Correct |
9 ms |
5608 KB |
Output is correct |
15 |
Correct |
9 ms |
5608 KB |
Output is correct |
16 |
Correct |
10 ms |
5608 KB |
Output is correct |
17 |
Correct |
10 ms |
5608 KB |
Output is correct |
18 |
Correct |
9 ms |
5608 KB |
Output is correct |
19 |
Correct |
10 ms |
5608 KB |
Output is correct |
20 |
Correct |
197 ms |
6788 KB |
Output is correct |
21 |
Correct |
195 ms |
6788 KB |
Output is correct |
22 |
Correct |
197 ms |
6788 KB |
Output is correct |
23 |
Correct |
201 ms |
6788 KB |
Output is correct |
24 |
Correct |
421 ms |
30640 KB |
Output is correct |
25 |
Correct |
454 ms |
30640 KB |
Output is correct |
26 |
Correct |
390 ms |
30640 KB |
Output is correct |
27 |
Correct |
356 ms |
35636 KB |
Output is correct |
28 |
Correct |
353 ms |
35692 KB |
Output is correct |
29 |
Correct |
377 ms |
35692 KB |
Output is correct |
30 |
Correct |
353 ms |
35692 KB |
Output is correct |
31 |
Correct |
411 ms |
35692 KB |
Output is correct |
32 |
Correct |
363 ms |
35692 KB |
Output is correct |
33 |
Correct |
307 ms |
35692 KB |
Output is correct |
34 |
Correct |
363 ms |
35692 KB |
Output is correct |
35 |
Correct |
316 ms |
35692 KB |
Output is correct |
36 |
Correct |
312 ms |
35692 KB |
Output is correct |
37 |
Correct |
389 ms |
35692 KB |
Output is correct |
38 |
Correct |
342 ms |
35692 KB |
Output is correct |
39 |
Correct |
491 ms |
35692 KB |
Output is correct |
40 |
Correct |
468 ms |
35692 KB |
Output is correct |
41 |
Correct |
1657 ms |
35692 KB |
Output is correct |
42 |
Correct |
459 ms |
35692 KB |
Output is correct |
43 |
Correct |
374 ms |
35692 KB |
Output is correct |
44 |
Incorrect |
218 ms |
35692 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |