Submission #1081815

#TimeUsernameProblemLanguageResultExecution timeMemory
1081815ThunnusBitaro’s Party (JOI18_bitaro)C++17
14 / 100
592 ms475448 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; #define int i64 #define vi vector<int> #define vvi vector<vi> #define vb vector<bool> #define pii pair<int, int> #define fi first #define se second #define sz(x) (int)(x).size() signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); const int SZ = 100; int n, m, q, a, b; cin >> n >> m >> q; vvi adj(n), radj(n); for(int i = 0; i < m; i++){ cin >> a >> b; adj[--a].emplace_back(--b); radj[b].emplace_back(a); } vector<vector<pii>> bestSZ(n); for(int v = 0; v < n; v++){ for(int &u : radj[v]){ for(pii &d : bestSZ[u]){ bestSZ[v].emplace_back(d.fi + 1, d.se); } } bestSZ[v].emplace_back(0, v); sort(bestSZ[v].begin(), bestSZ[v].end(), greater<pii>()); while(sz(bestSZ[v]) > SZ){ bestSZ[v].pop_back(); } } vb can(n, true); while(q--){ int t, y, ans = -1; cin >> t >> y; t--; vi yi(y); for(int i = 0; i < y; i++){ cin >> yi[i]; can[--yi[i]] = false; } if(y >= SZ){ vi dp(n, -1); dp[t] = 0; for(int v = t; v >= 0; v--){ if(dp[v] == -1) continue; if(can[v]) ans = max(ans, dp[v]); for(int &u : radj[v]){ dp[u] = max(dp[u], dp[v] + 1); } } } else{ for(pii &p : bestSZ[t]){ if(can[p.se]){ ans = p.fi; break; } } } for(int i = 0; i < y; i++){ can[yi[i]] = true; } cout << ans << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...