//start-time: 2024-04-14 19:39:32
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int w = 100;
void solve(){
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> gR(n);
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v;
gR[v - 1].push_back(u - 1);
}
vector<vector<pair<int, int>>> dp(n);
vector<int> vis(n), cur(n), val(n);
for(int u = 0; u < n; u++){
for(auto &v : gR[u]){
for(auto &[value, ind] : dp[v]){
if(vis[ind] == u) val[ind] = max(val[ind], value + 1);
else vis[ind] = u, val[ind] = value + 1, cur.push_back(ind);
}
}
for(auto v : cur) dp[u].push_back({val[v],v});
dp[u].push_back({0,u});
sort(dp[u].rbegin(), dp[u].rend());
if(dp[u].size()>w) dp[u].erase(dp[u].begin() + w, dp[u].end());
}
while(q--){
vector<bool> c(n);
int u, y, ans = -1;
cin >> u >> y;
u--;
for(int j = 0; j < y; j++){
int a; cin >> a;
c[--a] = 1;
}
if(y < w) {
for(auto &[v, i] : dp[u]){
if(!c[i]){
ans = max(ans, v);
}
}
}
else {
vector<int> naive(n);
for(int v = 0; v <= u; v++){
naive[v] = c[v] ? -1 : 0;
for(auto &el : gR[v]){
naive[v] = max(naive[v], naive[el] + (naive[el] != -1));
}
}
ans = naive[u];
}
cout << ans << endl;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
ll T = 1;
//cin >> T;
while(T--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
34 ms |
15196 KB |
Output is correct |
6 |
Correct |
30 ms |
15192 KB |
Output is correct |
7 |
Correct |
30 ms |
15192 KB |
Output is correct |
8 |
Correct |
32 ms |
15188 KB |
Output is correct |
9 |
Correct |
31 ms |
15180 KB |
Output is correct |
10 |
Correct |
31 ms |
15188 KB |
Output is correct |
11 |
Correct |
31 ms |
15200 KB |
Output is correct |
12 |
Correct |
31 ms |
15184 KB |
Output is correct |
13 |
Correct |
32 ms |
15192 KB |
Output is correct |
14 |
Correct |
47 ms |
16988 KB |
Output is correct |
15 |
Correct |
92 ms |
22248 KB |
Output is correct |
16 |
Correct |
37 ms |
15600 KB |
Output is correct |
17 |
Correct |
56 ms |
17764 KB |
Output is correct |
18 |
Correct |
35 ms |
15184 KB |
Output is correct |
19 |
Correct |
49 ms |
17552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
34 ms |
15196 KB |
Output is correct |
6 |
Correct |
30 ms |
15192 KB |
Output is correct |
7 |
Correct |
30 ms |
15192 KB |
Output is correct |
8 |
Correct |
32 ms |
15188 KB |
Output is correct |
9 |
Correct |
31 ms |
15180 KB |
Output is correct |
10 |
Correct |
31 ms |
15188 KB |
Output is correct |
11 |
Correct |
31 ms |
15200 KB |
Output is correct |
12 |
Correct |
31 ms |
15184 KB |
Output is correct |
13 |
Correct |
32 ms |
15192 KB |
Output is correct |
14 |
Correct |
47 ms |
16988 KB |
Output is correct |
15 |
Correct |
92 ms |
22248 KB |
Output is correct |
16 |
Correct |
37 ms |
15600 KB |
Output is correct |
17 |
Correct |
56 ms |
17764 KB |
Output is correct |
18 |
Correct |
35 ms |
15184 KB |
Output is correct |
19 |
Correct |
49 ms |
17552 KB |
Output is correct |
20 |
Correct |
114 ms |
17996 KB |
Output is correct |
21 |
Correct |
122 ms |
17976 KB |
Output is correct |
22 |
Correct |
113 ms |
18044 KB |
Output is correct |
23 |
Correct |
113 ms |
17956 KB |
Output is correct |
24 |
Runtime error |
1791 ms |
524288 KB |
Execution killed with signal 9 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
34 ms |
15196 KB |
Output is correct |
6 |
Correct |
30 ms |
15192 KB |
Output is correct |
7 |
Correct |
30 ms |
15192 KB |
Output is correct |
8 |
Correct |
32 ms |
15188 KB |
Output is correct |
9 |
Correct |
31 ms |
15180 KB |
Output is correct |
10 |
Correct |
31 ms |
15188 KB |
Output is correct |
11 |
Correct |
31 ms |
15200 KB |
Output is correct |
12 |
Correct |
31 ms |
15184 KB |
Output is correct |
13 |
Correct |
32 ms |
15192 KB |
Output is correct |
14 |
Correct |
47 ms |
16988 KB |
Output is correct |
15 |
Correct |
92 ms |
22248 KB |
Output is correct |
16 |
Correct |
37 ms |
15600 KB |
Output is correct |
17 |
Correct |
56 ms |
17764 KB |
Output is correct |
18 |
Correct |
35 ms |
15184 KB |
Output is correct |
19 |
Correct |
49 ms |
17552 KB |
Output is correct |
20 |
Correct |
114 ms |
17996 KB |
Output is correct |
21 |
Correct |
122 ms |
17976 KB |
Output is correct |
22 |
Correct |
113 ms |
18044 KB |
Output is correct |
23 |
Correct |
113 ms |
17956 KB |
Output is correct |
24 |
Runtime error |
1791 ms |
524288 KB |
Execution killed with signal 9 |
25 |
Halted |
0 ms |
0 KB |
- |