Submission #693198

#TimeUsernameProblemLanguageResultExecution timeMemory
693198four_specksBitaro’s Party (JOI18_bitaro)C++17
0 / 100
0 ms212 KiB
#include <bits/stdc++.h> using namespace std; namespace { } // namespace void solve() { const int SQ = 20; int n, m, q; cin >> n >> m >> q; vector<vector<int>> adj(n), adj_rev(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v, --u, --v; adj[v].push_back(u); } vector<vector<pair<int, int>>> take(n); if (0) for (int i = 0; i < n; i++) { take[i].emplace_back(0, i); for (int j : adj[i]) { for (auto [l, k] : take[j]) take[i].emplace_back(l + 1, k); } sort(take[i].begin(), take[i].end()); take[i].erase(unique(take[i].begin(), take[i].end()), take[i].end()); if ((int)take[i].size() > SQ) take[i].erase(take[i].begin() + SQ, take[i].end()); } vector<bool> bad(n); for (int c = 0; c < q; c++) { int u, y; cin >> u >> y, --u; vector<int> busy(y); for (int &v : busy) cin >> v, --v; for (int v : busy) bad[v] = 1; if (y >= SQ) { vector<int> dp(u + 1); for (int v : busy) dp[v] = -1; for (int i = 0; i <= u; i++) { for (int j : adj[i]) { if (dp[j] != -1) dp[i] = max(dp[i], dp[j] + 1); } } cout << dp[u] << '\n'; } else { int res = -1; for (auto [l, v] : take[u]) { if (!bad[v]) res = max(res, l); } cout << res << '\n'; } for (int v : busy) bad[v] = 0; } } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...