제출 #1331128

#제출 시각아이디문제언어결과실행 시간메모리
1331128silence25Bitaro’s Party (JOI18_bitaro)C++20
0 / 100
1 ms344 KiB
#include "bits/stdc++.h"

using namespace std;

#define ff first
#define ss second
#define pp pop_back
#define ll long long
#define pb push_back
#define pq priority_queue
#define ls(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define wr cout << "------------------------" << endl
#define tt debug

const int N = 1e5 + 5;
int dist[N];
vector<int>g[N];
bool banned[N];

void dfs(int nd){
    for(auto it:g[nd]){
        if(dist[it] < dist[nd] + 1){
            dist[it] = dist[nd] + 1;
            dfs(it);
        }
    }
}

signed main(){
#ifdef parad0x
    freopen("file.in","r",stdin);
#endif
    #define print(...) 42

    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n,m,q;
    cin >> n >> m >> q;
    for(int i = 1,a,b;i<=m;++i){
        cin >> a >> b;
        g[b].pb(a);
    }
    while(q--){
        int x;
        cin >> x;
        fill(banned + 1,banned + 1 + n,false);
        fill(dist + 1,dist + 1 + n,0);
        dist[x] = 0;
        dfs(x);
        int lens;
        cin >> lens;
        for(int i = 1,a;i<=lens;++i){
            cin >> a;
            banned[a] = true;
        }
        int ans = 0;
        for(int i = 1;i<=n;++i){
            if(!banned[i]){
                ans = max(ans,dist[i]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...