Submission #1087726

#TimeUsernameProblemLanguageResultExecution timeMemory
1087726MahogBitaro’s Party (JOI18_bitaro)C++17
100 / 100
507 ms146132 KiB
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 2; const int s = 100; const int oo = -1e9; int vis[MAX], f[MAX], n, m, q; vector<int> a[MAX], v; vector<pair<int, int>> b[MAX]; void solve() { cin >> n >> m >> q; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; a[v].push_back(u); } fill(vis + 1, vis + n + 1, -1); for (int i = 1; i <= n; i++) { b[i].push_back({0, i}); for (auto j : a[i]) { for (auto [dist, idx] : b[j]) { if (vis[idx] == -1) { vis[idx] = dist + 1; v.push_back(idx); } else { vis[idx] = max(vis[idx], dist + 1); } } } for (auto j : v) { b[i].push_back({vis[j], j}); vis[j] = -1; } sort(b[i].begin(), b[i].end(), greater<pair<int, int>>()); while (b[i].size() > s) b[i].pop_back(); v.clear(); } /*for (int i = 1; i <= n; i++) { for (auto [dist, idx] : b[i]) cout << dist << " " << idx << "\n"; cout << "\n"; }*/ fill(vis + 1, vis + n + 1, 0); for (int i = 1; i <= q; i++) { int t, y; cin >> t >> y; for (int j = 1; j <= y; j++) { int x; cin >> x; vis[x] = 1; v.push_back(x); } if (y >= s) { fill(f + 1, f + t + 1, -1); f[t] = 0; int res = -1; for (int j = t; j >= 1; j--) { if (f[j] == -1) continue; for (auto v : a[j]) { f[v] = max(f[v], f[j] + 1); } } for (int j = 1; j <= t; j++) { if (!vis[j]) res = max(res, f[j]); } cout << res << "\n"; } else { int res = -1; for (auto [dist, idx] : b[t]) { if (!vis[idx]) { res = dist; break; } } cout << res << "\n"; } for (auto j : v) vis[j] = 0; v.clear(); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...