Submission #963297

#TimeUsernameProblemLanguageResultExecution timeMemory
963297TimAniBitaro’s Party (JOI18_bitaro)C++17
100 / 100
889 ms151556 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back const int mxN = (int)2e5+2; const int B = 100; int n, m, Q, a, b; vector<int> adj[mxN], cur; vector<array<int,2>> node[mxN]; int bad[mxN], vis[mxN], dis[mxN], dp[mxN]; int main() { cin >> n >> m >> Q; for(int i = 0; i < m; i++) cin >> a >> b, adj[b].pb(a); for(int i = 1; i <= n; i++, cur.clear()){ for(auto j : adj[i]){ for(auto [w,u] : node[j]){ if(vis[u]==i) dis[u] = max(dis[u], w+1); else vis[u]=i, dis[u] = w+1, cur.pb(u); } } for(auto u : cur) node[i].pb({dis[u],u}); node[i].pb({0,i}); sort(rbegin(node[i]),rend(node[i])); if(node[i].size()>B) node[i].erase(begin(node[i])+B,end(node[i])); } for(int q = 1; q <= Q; q++){ int t, k, x, ans=-1; cin >> t >> k; for(int i = 0; i < k; i++) cin >> x, bad[x]=q; if(k<B){ for(auto [w,u] : node[t]){ if(bad[u]!=q){ ans=w; break; } } } else{ fill(dp, dp+n+1, -1); for(int i = 1; i <= t; i++){ if(bad[i]!=q) dp[i]=0; for(auto j : adj[i]) if(dp[j]!=-1) dp[i] = max(dp[i],dp[j]+1); } ans = dp[t]; } cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...