Submission #365785

#TimeUsernameProblemLanguageResultExecution timeMemory
365785Jarif_RahmanBitaro’s Party (JOI18_bitaro)C++17
7 / 100
2100 ms199672 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int sq;
vector<bool> bl;
void merge(vector<pair<int, int>> a, vector<pair<int, int>> &b){
    vector<pair<int, int>> c;
    for(int i = 0; i < b.size(); i++) c.pb(b[i]);
    b.clear();
    for(int i = 0; i < a.size(); i++) c.pb(a[i]);
    sort(c.rbegin(), c.rend());
    for(int i = 0; i < c.size(); i++){
        if(b.size() >= sq) break;
        if(!bl[c[i].sc]) b.pb(c[i]), bl[c[i].sc] = 1;
    }
    for(int i = 0; i < b.size(); i++) bl[b[i].sc] = 0;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, q; cin >> n >> m >> q;
    bl.resize(n, 0);
    sq = sqrt(n+0.0);
    vector<vector<int>> v(n);
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b; a--, b--;
        v[a].pb(b);
    }
    vector<vector<pair<int, int>>> dps(n);
    for(int i = 0; i < n; i++){
        if(dps[i].size() < sq) dps[i].pb({0, i});
        vector<pair<int, int>> mg;
        for(auto [c, nd]: dps[i]) mg.pb({c+1, nd});
        for(int x: v[i]) merge(mg, dps[x]);
    }
    vector<bool> busy(n, 0);
    while(q--){
        int tj, yj; cin >> tj >> yj;
        tj--;
        vector<int> cbs(yj);
        for(int &x: cbs) cin >> x, x--, busy[x] = 1;
        if(yj < (int)dps[tj].size()){
            int ans = -1;
            for(auto [c, nd]: dps[tj]) if(!busy[nd]) ans = max(ans, c);
            cout << ans << "\n";
            for(int x: cbs) busy[x] = 0;
            continue;
        }
        vector<int> dp(n, -1);
        for(int i = 0; i < n; i++){
            if(busy[i] && dp[i] == -1) continue;
            dp[i] = max(dp[i], 0);
            for(int x: v[i]) dp[x] = max(dp[x], dp[i]+1);
        }
        cout << dp[tj] << "\n";
        for(int x: cbs) busy[x] = 0;
    }
}

Compilation message (stderr)

bitaro.cpp: In function 'void merge(std::vector<std::pair<int, int> >, std::vector<std::pair<int, int> >&)':
bitaro.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < b.size(); i++) c.pb(b[i]);
      |                    ~~^~~~~~~~~~
bitaro.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i = 0; i < a.size(); i++) c.pb(a[i]);
      |                    ~~^~~~~~~~~~
bitaro.cpp:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 0; i < c.size(); i++){
      |                    ~~^~~~~~~~~~
bitaro.cpp:17:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |         if(b.size() >= sq) break;
      |            ~~~~~~~~~^~~~~
bitaro.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 0; i < b.size(); i++) bl[b[i].sc] = 0;
      |                    ~~^~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:35:26: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |         if(dps[i].size() < sq) dps[i].pb({0, i});
      |            ~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...