# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
981813 | blackslex | Bitaro’s Party (JOI18_bitaro) | C++17 | 0 ms | 0 KiB |
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;
using pii = pair<int, int>;
using P = pair<pii, int>;
const int N = 1e5 + 5, K = 320;
int n, m, q, x, y, t, r, ptr[N], cdp[N];
vector<int> v[N], rev[N];
vector<pii> dp[N];
int main() {
scanf("%d %d %d", &n, &m, &q);
while (m--) scanf("%d %d", &x, &y), v[x].emplace_back(y), rev[y].emplace_back(x);
for (int i = 1; i <= n; i++) cdp[i] = -1e9;
for (int i = 1; i <= n; i++) {
priority_queue<P> pq;
pq.emplace(pii(0, i), n + 1);
for (auto &e: rev[i]) {
auto [x, y] = dp[e][0];
pq.emplace(pii(x + 1, y), e);
ptr[e] = 1;
}
while (!pq.empty() && dp[i].size() <= k) {
auto [x, y] = pq.top(); pq.pop();
dp[i].emplace_back(x);
if (ptr[y] < dp[y].size()) {
auto [cx, cy] = dp[y][ptr[y]]; ptr[y]++;
pq.emplace(pii(cx + 1, cy), y);
}
}
}
vector<bool> f(n + 5);
while (q--) {
scanf("%d %d", &t, &r);
vector<int> c(r);
for (auto &e: c) scanf("%d", &e), f[e] = 1;
int ans = -1;
if (r < k) {
for (auto &[x, y]: dp[t]) if (!f[y]) {ans = x; break;}
} else {
cdp[t] = 0;
for (int i = t; i >= 1; i--) {
for (auto &e: v[i]) cdp[i] = max(cdp[i], cdp[e] + 1);
if (!f[i]) ans = max(ans, cdp[i]);
}
for (int i = t; i >= 1; i--) cdp[i] = -1e9;
}
printf("%d\n", ans);
for (auto &e: c) f[e] = 0;
}
}