Submission #683738

#TimeUsernameProblemLanguageResultExecution timeMemory
683738saayan007Bitaro’s Party (JOI18_bitaro)C++14
14 / 100
2092 ms12532 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<long long>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<long long, long long>>;

#define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i)
#define fr first 
#define sc second
#define mp make_pair
#define pb emplace_back
#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const ll inf = 1e18L;

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

    ll n, m, q;
    cin >> n >> m >> q;
    vl adj[n + 1];
    fur(i, 1, m) {
        ll l, r;
        cin >> l >> r;
        adj[l].pb(r);
    }

    while(q--) {
        ll t, y;
        cin >> t >> y;
        set<ll> s;
        fur(rep, 1, y) {
            ll a;
            cin >> a;
            s.insert(a);
        }

        ll dp[n + 1];
        fur(i, 1, n) {
            if(!s.count(i) && i <= t) {
                dp[i] = 0;
            } else {
                dp[i] = -inf;
            }
        }

        fur(i, 1, t) {
            for(auto j : adj[i]) {
                dp[j] = max(dp[j], dp[i] + 1);
            }
        }
        cout << (dp[t] < 0 ? -1 : dp[t]) << nl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...