Submission #1261369

#TimeUsernameProblemLanguageResultExecution timeMemory
1261369hoa208Bitaro’s Party (JOI18_bitaro)C++20
7 / 100
2021 ms26288 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const   ll mod = 1e9 + 7;
const   ll INF = 1e18;
inline  void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;}
//--------------------------------------------------------------------

ll n, m, q;
const ll N = 1e5 + 10;
vector<ll> g[N], h[N];
vector<pa> ens[N];
const int BLOCK = 316;
ll dx[N], c[N], dp[N];
void hbmt() {
    cin >> n >> m >> q;
    FOR(i, 1, m) {
        ll u, v;
        cin >> u >> v;
        g[u].push_back(v);
        h[v].push_back(u);
    }
    FOR(i, 1, n) {
        vector<pa> vt;
        for(auto v : h[i]) {
            for(auto e : ens[v]) {
                vt.push_back({e.fi + 1, e.se});
            }
        }
        sort(vt.begin(), vt.end(), [&] (pa &x, pa &y) {
            return x.fi > y.fi;
        });
        int cnt = 0;
        for(auto e : vt) {
            if(dx[e.se] == 1) continue;
            dx[e.se] = 1;
            cnt++;
            ens[i].push_back(e);
            if(cnt >= BLOCK + 2) {
                break;
            }
        }
        ens[i].push_back({0, i});
        for(auto e : vt) {
            dx[e.se] = 0;
        }
    }
    FOR(i, 1, q) {
        ll t, y;
        cin >> t >> y;
        FOR(j, 1, y) {
            cin >> c[j];
            dx[c[j]] = 1;
        }
        if(y <= BLOCK) {
            bool ok = false;
            for(auto e : ens[t]) {
                if(dx[e.se] == 0) {
                    cout << e.fi << '\n';
                    ok = true;
                    break;
                }
            }
            if(!ok) cout << -1 << '\n';
        }
        else {
            fill(dp + 1, dp + t + 1, -1);
            FOR(i, 1, t) {
                if(!dx[i]) {
                    dp[i] = max(0LL, dp[i]);
                }
                if(dp[i] == -1) continue;
                for(auto v : g[i]) {
                    dp[v] =  max(dp[i] + 1, dp[v]);                    
                }
            }
            cout << dp[t] << '\n';
        }
        FOR(j, 1, y) {
            dx[c[j]] = 0;
        }
    }
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    
    if(fopen("hbmt.inp", "r")) {
        freopen("hbmt.inp", "r", stdin);
        freopen("hbmt.out", "w", stdout);
    }
    
    // t_test 
    hbmt();
    return 0;
}

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen("hbmt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen("hbmt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...