Submission #400389

#TimeUsernameProblemLanguageResultExecution timeMemory
400389nikatamlianiBitaro’s Party (JOI18_bitaro)C++14
14 / 100
1231 ms91740 KiB
#include <bits/stdc++.h> using namespace std; void maxi(int &x, int y) { if(x < y) x = y; } const int C = 100; bool vis[100005]; void merge(vector<pair<int, int>> &a, const vector<pair<int, int>> &b) { vector<pair<int, int>> c(C); int ptr = -1; int n = (int)a.size(), m = (int)b.size(); for(int i = 0, j = 0; i < n || j < m;) { if(i+j >= C) break; if(i < n && vis[a[i].second]) { ++i; continue; } if(j < m && vis[b[j].second]) { ++j; continue; } if(j == m || (i < n && a[i].first > b[j].first+1)) { c[++ptr] = a[i]; vis[a[i++].second] = 1; } else { c[++ptr] = {b[j].first+1, b[j].second}; vis[b[j++].second] = 1; } } while((int)c.size() > ptr+1) c.pop_back(); for(const auto &p : c) vis[p.second] = 0; a = c; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; vector<vector<int>> g(n+1); vector<vector<int>> r(n+1); for(int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); r[v].push_back(u); } vector<int> dst(n+1); vector<vector<pair<int, int>>> list(n+1); for(int i = 1; i <= n; ++i) { for(int x : r[i]) { merge(list[i], list[x]); } if((int)list[i].size() < C) list[i].push_back({0, i}); } vector<bool> blocked(n+1); vector<int> dp(n+1); while(q--) { int t, x; cin >> t >> x; vector<int> v(x); for(int i = 0; i < x; ++i) { cin >> v[i]; blocked[v[i]] = 1; } int ans = -1; if(x < C) { for(pair<int, int> p : list[t]) { if(!blocked[p.second]) { ans = p.first; break; } } } else { for(int i = 1; i <= t; ++i) { dp[i] = -1e6; if(!blocked[i]) { dp[i] = 0; } for(int x : r[i]) { maxi(dp[i], dp[x]+1); } } ans = dp[t]; } if(ans < 0) ans = -1; cout << ans << '\n'; for(int i : v) blocked[i] = 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...