Submission #1017022

#TimeUsernameProblemLanguageResultExecution timeMemory
1017022PekibanBitaro’s Party (JOI18_bitaro)C++17
0 / 100
3 ms996 KiB
#include <bits/stdc++.h>

using namespace std;

const int K = 100, mxN = 1e5+2;

bool vis[mxN];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> fw[n+1], bc[n+1];
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        fw[u].push_back(v), bc[v].push_back(u);
    }
    vector<array<int, 2>> a[n+1];
    for (int i = 1; i <= n; ++i) {
        sort(fw[i].begin(), fw[i].end());
        priority_queue<array<int, 3>> pq;
        for (auto x : bc[i]) {
            pq.push({a[x][0][0], x, 0});
        }
        while (a[i].size() < K && !pq.empty()) {
            auto [d, id, c] = pq.top();
            pq.pop();
            if (!vis[a[id][c][1]]) a[i].push_back({d+1, a[id][c][1]});
            vis[a[id][c][1]] = 1;
            if (c+1 != a[id].size())  pq.push({a[id][c+1][0], id, c+1});
        }
        for (auto x : a[i])    vis[x[1]] = 0;
        if (a[i].size() < K)    a[i].push_back({0, i});
    }
    int di[n+1];
    while (q--) {
        int t, y;
        cin >> t >> y;
        vector<int> v(y);
        for (int i = 0; i < y; ++i) {
            cin >> v[i];
            vis[v[i]] = 1;
        }
        int ans = -1;
        if (y < K) {
            for (auto [d, i] : a[t]) {
                if (!vis[i]) {
                    ans = d;
                    break;
                }
            }
        }
        else {
            for (int i = t; i >= 1; --i) {
                di[i] = -1e9;
                for (auto u : fw[i]) {
                    if (u > t)  break;
                    di[i] = max(di[u] + 1, di[i]);
                }
                if (!vis[i])    ans = max(ans, di[i]);
            }    
        }
        for (int i = 0; i < y; ++i) {
            vis[v[i]] = 0;
        }
        cout << ans << '\n';
    }
}

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:31:21: warning: comparison of integer expressions of different signedness: 'std::tuple_element<2, std::array<int, 3> >::type' {aka 'int'} and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             if (c+1 != a[id].size())  pq.push({a[id][c+1][0], id, c+1});
      |                 ~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...