Submission #531075

#TimeUsernameProblemLanguageResultExecution timeMemory
5310754fectaBitaro’s Party (JOI18_bitaro)C++17
14 / 100
2049 ms23660 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)

const int MN = 200005;

int n, m, q, u, v, k, dp[MN];
vector<int> a[MN], r[MN];

int32_t main() {
    boost();

    cin >> n >> m >> q;
    for (int i = 1; i <= m; i++) {
        cin >> u >> v;
        a[u].push_back(v);
        r[v].push_back(u);
    }
    for (int i = 1; i <= q; i++) {
        cin >> u >> k;
        set<int> s;
        for (int j = 1; j <= k; j++) cin >> v, s.insert(v);
        int ans = -1;
        dp[u] = 0;
        if (!s.count(u)) ans = 0;
        for (int j = u - 1; j > 0; j--) {
            dp[j] = -0x3f3f3f3f;
            for (int nxt : a[j]) if (nxt <= u) dp[j] = max(dp[j], dp[nxt] + 1);
            if (!s.count(j)) ans = max(ans, dp[j]);
        }
        printf("%lld\n", ans);
    }

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