Submission #204108

#TimeUsernameProblemLanguageResultExecution timeMemory
204108extraterrestrialBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1341 ms115156 KiB
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; #define F first #define S second #define pb push_back #define all(x) (x).begin(), (x).end() #define SZ(x) (int)(x).size() //#define int ll const int N = 1e5 + 10; const int B = 100; const int INF = 1e9 + 10; vector<pair<int, int>> best[N]; vector<int> g[N]; int used[N], timer, dp[N], ptr[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; g[v].pb(u); } for (int i = 1; i <= n; i++) { timer++; set<pair<int, int>> st; for (int v : g[i]) { ptr[v] = 0; st.insert({-best[v][0].F, v}); } while (!st.empty() && SZ(best[i]) < B) { int v = st.begin()->S; st.erase(st.begin()); if (used[best[v][ptr[v]].S] < timer) { used[best[v][ptr[v]].S] = timer; best[i].pb(make_pair(best[v][ptr[v]].F + 1, best[v][ptr[v]].S)); } ptr[v]++; if (ptr[v] < SZ(best[v])) { st.insert(make_pair(-best[v][ptr[v]].F, v)); } } if (SZ(best[i]) < B) { best[i].pb(make_pair(0, i)); } } for (int i = 0; i < q; i++) { int v; cin >> v; int cnt; cin >> cnt; timer++; for (int j = 0; j < cnt; j++) { int x; cin >> x; used[x] = timer; } if (cnt < B) { int res = -1; for (auto it : best[v]) { if (used[it.S] < timer) { res = it.F; break; } } cout << res << '\n'; } else { for (int i = 1; i <= v; i++) { if (used[i] == timer) { dp[i] = -INF; } else { dp[i] = 0; } for (int v : g[i]) { dp[i] = max(dp[i], dp[v] + 1); } //cout << dp[i] << ' '; } //cout << '\n'; cout << (dp[v] < 0 ? -1 : dp[v]) << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...