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 <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 200005, BLK = 50;
int n, m, q, u, v, k, dp[MN], s[MN], rem[MN];
vector<int> a[MN], r[MN];
vector<pii> far[MN];
bool cmp(pii p, pii q) {
if (p.s != q.s) return p.s < q.s;
return p.f > q.f;
}
int32_t main() {
boost();
cin >> n >> m >> q;
for (int i = 1; i <= m; i++) {
cin >> u >> v;
a[u].push_back(v);
r[v].push_back(u);
}
for (int i = 1; i <= n; i++) {
far[i].push_back({0, i});
for (int j : r[i]) for (pii p : far[j]) far[i].push_back({p.f + 1, p.s});
sort(far[i].begin(), far[i].end(), cmp);
vector<pii> tmp;
int pre = -1;
for (pii p : far[i]) if (p.s != pre) {pre = p.s; tmp.push_back(p);}
far[i] = tmp;
sort(far[i].begin(), far[i].end(), greater<>());
while (far[i].size() > BLK) far[i].pop_back();
}
for (int i = 1; i <= q; i++) {
cin >> u >> k;
for (int j = 1; j <= k; j++) cin >> rem[j], s[rem[j]] = 1;
if (k >= BLK) {
for (int j = 1; j <= u; j++) {
if (!s[j]) dp[j] = 0;
else dp[j] = -1;
for (int p : r[j]) if (dp[p] != -1) dp[j] = max(dp[j], dp[p] + 1);
}
printf("%lld\n", dp[u]);
} else {
int ans = -1;
for (pii p : far[u]) if (!s[p.s]) {ans = p.f; break;}
printf("%lld\n", ans);
}
for (int j = 1; j <= k; j++) s[rem[j]] = 0;
}
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... |