Submission #1115595

#TimeUsernameProblemLanguageResultExecution timeMemory
1115595LonlyRBitaro’s Party (JOI18_bitaro)C++17
14 / 100
1386 ms126600 KiB
#include<bits/stdc++.h> #define ii pair<int,int> using namespace std; const int maxn = 2e5 + 5, bl = 100; int n, m, q; int dp[maxn], mark[maxn]; vector<int> adj[maxn], radj[maxn]; vector<ii> path[maxn]; void precompute() { for (int i = 1; i <= n; i++) { priority_queue<ii, vector<ii>, greater<ii>> pq; pq.emplace(0, i); for (int j : adj[i]) { for (auto [u, v] : path[j]) { pq.emplace(u + 1, v); if (pq.size() > bl) pq.pop(); } } while (pq.size()) path[i].emplace_back(pq.top()), pq.pop(); reverse(path[i].begin(), path[i].end()); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("test.inp", "r", stdin); // freopen("test.out", "w", stdout); cin >> n >> m >> q; for (int i = 1, u, v; i <= m; i++) cin >> u >> v, adj[v].emplace_back(u), radj[u].emplace_back(v); precompute(); while (q--) { int T, k, x, ans = -1; cin >> T >> k; vector<int> qr; while (k--) cin >> x, qr.emplace_back(x), mark[x] = 1; if (qr.size() >= bl) { for (int i = 0; i <= n; i++) dp[i] = -2e9; int oo = dp[0]; dp[T] = 0; for (int i = n; i >= 1; i--) { for (int j : radj[i]) if (dp[j] != oo) dp[i] = max(dp[i], dp[j] + 1); if (dp[i] != oo && !mark[i]) ans = max(ans, dp[i]); } } else { for (auto [u, v] : path[T]) if (!mark[v]) { ans = u; break; } } cout << ans << "\n"; for (int i : qr) mark[i] = 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...