Submission #963286

#TimeUsernameProblemLanguageResultExecution timeMemory
963286TimAniBitaro’s Party (JOI18_bitaro)C++17
7 / 100
2016 ms44868 KiB
//start-time: 2024-04-14 19:39:32 #include <vector> #include <set> #include <iostream> #include <algorithm> #include <array> using namespace std; using ll = long long; const int w = 200; void solve(){ int n, m, q; cin >> n >> m >> q; vector<vector<int>> gR(n); for(int i = 0; i < m; i++){ int u, v; cin >> u >> v; u--; v--; gR[v].push_back(u); } vector<vector<array<int, 2>>> dp(n); vector<int> val(n, -1); set<array<int, 2>> aux; for(int u = 0; u < n; u++){ val.assign(n, -1); aux.clear(); aux.insert({0, u}); val[u] = 0; for(auto v : gR[u]){ for(auto [value, ind] : dp[v]){ val[ind] = max(val[ind], value + 1); } } for(auto v : gR[u]){ for(auto [value, ind] : dp[v]){ aux.insert({val[ind], ind}); if(aux.size() > w){ aux.erase(aux.begin()); } } } dp[u] = vector<array<int, 2>>(aux.begin(), aux.end()); } vector<bool> c(n); vector<int> naive(n); for(int i = 0; i < q; i++){ c.assign(n, 0); int u, y; cin >> u >> y; u--; for(int j = 0; j < y; j++){ int a; cin >> a; c[--a] = 1; } int ans = -1; if(y < w) { for(auto [v, i] : dp[u]){ if(!c[i]){ ans = max(ans, v); } } } else { naive.assign(n, 0); for(int v = 0; v <= u; v++){ naive[v] = c[v] ? -1 : 0; for(auto el : gR[v]){ naive[v] = max(naive[v], naive[el] + (naive[el] != -1)); } } ans = naive[u]; } cout << ans << endl; } } int main() { cin.tie(0)->sync_with_stdio(0); ll T = 1; //cin >> T; while(T--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...