Submission #731101

#TimeUsernameProblemLanguageResultExecution timeMemory
731101vjudge1Bitaro’s Party (JOI18_bitaro)C++17
0 / 100
2079 ms102028 KiB
#include <bits/stdc++.h>
#define sts stable_sort
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define F first
#define S second
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define eb emplace_back
#define ll long long
#define ui unsigned int
#define ull unsigned long long

using namespace std;

const int MAXN = 1e4 + 4;
const int MOD = 1e9 + 7;
const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
vector<int> add[MAXN];
bool inv[MAXN];
bool comp[MAXN][MAXN];
int dist[MAXN];

void f(int nod){
    queue<pair<int, int> > q;
    q.push({nod, 0});

    while(!q.empty()){
        pair<int, int> x = q.front();
        q.pop();

        if(x.F > nod)continue;

        comp[nod][x.F] = 1;
        dist[x.F] = x.S;

        for(auto &c : add[x.F]){
            q.push({c, x.S + 1});
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n, m, Q; cin >> n >> m >> Q;

    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;

        add[b].pb(a);
    }

    while(Q--){
        int a, b; cin >> a >> b;

        for(int i = 0; i < b; i++){
            int x; cin >> x;

            inv[x] = 1;
        }
        int maxi = -1;

        f(a);

        for(int i = 1; i <= a; i++){
            if(inv[i]){
                inv[i] = 0;
                continue;
            }
            if(!comp[a][i])continue;
            maxi = max(maxi, dist[i]);
        }
        cout << maxi << "\n";
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...