Submission #531163

#TimeUsernameProblemLanguageResultExecution timeMemory
5311634fectaBitaro’s Party (JOI18_bitaro)C++17
14 / 100
2000 ms481840 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, BLK = 100; int n, m, q, u, v, k, dp[MN]; vector<int> a[MN], r[MN]; vector<pii> far[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 <= n; i++) { far[i].push_back({0, i}); for (int j : r[i]) for (pii p : far[j]) far[i].push_back({p.f + 1, p.s}); sort(far[i].begin(), far[i].end(), greater<>()); while (far[i].size() > BLK) far[i].pop_back(); } 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); if (k >= BLK) { 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); } else { int ans = -1; for (pii p : far[u]) if (!s.count(p.s)) {ans = p.f; break;} printf("%lld\n", ans); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...