Submission #1349236

#TimeUsernameProblemLanguageResultExecution timeMemory
1349236mitko7Bitaro’s Party (JOI18_bitaro)C++20
0 / 100
2 ms580 KiB
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <set>
#include <cstring>
#define endl '\n'
using namespace std;
vector<int> v[600000];
bool ne[100005];
int dp[100005];
bool used[100005];
bool ok[100005];
void dfs(int i) {
    used[i]=1;
    for(auto x : v[i]) {
        if(!used[x]) dfs(x);
        if(ok[x]) {
            ok[i]=1;
            dp[i]=max(dp[i], dp[x]+1);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m,q; cin >> n >> m >> q;
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }
    
    while(q--) {
        int t,y; cin >> t >> y;
        while(y--) {
            int a; cin >> a;
            ne[a]=1;
        }
        dp[t]=0;
        ok[t]=1;
        for(int i = 1; i <= n; i++) {
            if(!used[i]) {
                dfs(i);
            }
        }
        int ans=-1;
        for(int i = 1; i <= n; i++) {
            if(ne[i]) continue;
            ans=max(ans, dp[i]);
        }
        cout << ans << endl;
        memset(ne, 0, sizeof(ne));
        memset(used, 0, sizeof(used));
        memset(ok, 0, sizeof(ok));
        for(int i = 1; i <= n; i++) dp[i]=-1;
    }
}
/*
5 6 1
1 2
2 4
3 4
1 3
3 5
4 5
5 2 2 3
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...