Submission #1018276

#TimeUsernameProblemLanguageResultExecution timeMemory
1018276ThommyDBBitaro’s Party (JOI18_bitaro)C++17
0 / 100
399 ms48656 KiB
#include<bits/stdc++.h>

using namespace std;
#define int long long

int N, M, Q;
//vector<pair<int, int>> Canals;
vector<vector<int>> adj;
vector<vector<int>> C;
map<pair<int, int>, int> dp;

int n;

int dfs(int x){
    if(dp[{x,x}]==-1)return 1;
    dp[{x, x}]=-1;
    for(auto u : adj[x]){
        dfs(u);
        dp[{x,u}]= max(dp[{x,u}], (int)1);
        for(int i = x+1; i < N; i++){
            if(dp[{u,i}]==-1)continue;
            dp [{x,i}] = max(dp[{x,i}], dp[{u,i}]+1);
        }
    }
    return 1;
}

signed main(){
    cin >> N >> M >> Q;
    n=N-1;
    //Canals.resize(M);
    adj.resize(N);
    int s, e;
    for(int i = 0; i < M; i++){
        //cin >> Canals[i].first >> Canals[i].second;
        //Canals[i].first--; Canals[i].second--;
        //adj[Canals[i].first].push_back(Canals[i].second);
        cin >> s >> e;
        s--; e--;
        adj[s].push_back(e);
    }
    for(int i = 0; i < N; i++){
        if(dp[{i,i}]==-1)continue;
        dfs(i);
    }
    

    /*for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cout << i << " -> " << j << " = " << dp[i][j] << "\n";
        }
    }*/

    int T;
    int Y;
    C.resize(Q);
    vector<bool> TooBusy(N, false);
    for(int i = 0; i < Q; i++){
        fill(TooBusy.begin(), TooBusy.end(), false); // Replace with changing every Y[i] back at the end
        cin >> T >> Y;
        T--;
        C[i].resize(Y);
        for(int j = 0; j < Y; j++){
            cin >> C[i][j];
            C[i][j]--;
            TooBusy[C[i][j]]=true;
        }
        int ans = -1;
        for(int j = 0; j < N; j++){
            //cout << i << " && " << T[i] << "\n";
            if(TooBusy[j])continue;
            if(dp[{j, T}] == -1) ans = max(ans, (int)0);
            if(dp[{j, T}] == 0) ans = max(ans, (int)-1);
            continue;
            ans = max(ans, dp[{j,T}]);
        }
        cout << ans << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...