This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int INF = 1e9;
int n, m, q;
vector<vector<int>> g;
int comptueAns(int t, bool is_busy[]) {
int dp[t + 1];
for (int u = 0; u <= t; u++) {
dp[u] = -INF;
for (int v : g[u]) {
dp[u] = max(dp[u], dp[v] + 1);
}
if (not is_busy[u]) dp[u] = max(dp[u], 0);
}
return max(dp[t], -1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> q;
g.resize(n);
while (m--) {
int u, v;
cin >> u >> v;
u--, v--;
g[v].push_back(u);
}
vector<int> busy_ppl;
bool is_busy[n] = {0};
while (q--) {
int t, y;
cin >> t >> y;
t--;
busy_ppl.resize(y);
for (int &c : busy_ppl) {
cin >> c;
c--;
is_busy[c] = 1;
}
cout << comptueAns(t, is_busy) << '\n';
for (int &c : busy_ppl) {
is_busy[c] = 0;
}
busy_ppl.clear();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |