Submission #1363474

#TimeUsernameProblemLanguageResultExecution timeMemory
1363474kawhietBitaro’s Party (JOI18_bitaro)C++20
0 / 100
2 ms836 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif

constexpr int B = 100;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[y].push_back(x);
    }
    vector<vector<array<int, 2>>> f(n);
    vector<int> dp(n, -1);
    for (int i = 0; i < n; i++) {
        f[i].push_back({0, i});
        vector<int> pos;
        for (int j : g[i]) {
            for (auto [w, k] : f[j]) {
                if (dp[k] == -1) {
                    dp[k] = w + 1;
                    pos.push_back(k);
                } else {
                    dp[k] = max(dp[k], w + 1);
                }
            }
        }
        for (int j : pos) {
            f[i].push_back({dp[j], j});
        }
        sort(f[i].rbegin(), f[i].rend());
        while (f[i].size() > B) {
            f[i].pop_back();
        }
        for (int j : pos) {
            dp[j] = -1;
        }
    }
    vector<bool> blocked(n);
    while (q--) {
        int t, k;
        cin >> t >> k;
        t--;
        vector<int> y(k);
        for (int i = 0; i < k; i++) {
            cin >> y[i];
            blocked[--y[i]] = true;
        }
        int ans = -1;
        if (k >= B) {
            vector<int> dp(t + 1, -1e9);
            dp[t] = 0;
            for (int i = t; i >= 0; i--) {
                if (!blocked[i]) {
                    ans = max(ans, dp[i]);
                }
                for (int j : g[i]) {
                    dp[j] = min(dp[j], dp[i] + 1);
                }
            }
        } else {
            for (auto [x, u] : f[t]) {
                if (!blocked[u]) {
                    ans = x;
                    break;
                }
            }
        }
        cout << ans << '\n';
        for (int i : y) {
            blocked[i] = false;
        }
    }
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...