제출 #1087669

#제출 시각아이디문제언어결과실행 시간메모리
1087669MahogBitaro’s Party (JOI18_bitaro)C++17
0 / 100
4 ms5468 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); } 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]) { 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] = 0; } 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"; }*/ 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]++; v.push_back(x); } if (y >= s) { fill(f + 1, f + t + 1, 0); f[t] = 0; int res = -1; for (int j = t; j >= 1; j--) { if (vis[j]) continue; for (auto v : a[j]) { if (!vis[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 check = 0; for (auto [dist, idx] : b[t]) { if (!vis[idx]) { check = 1; cout << dist << "\n"; break; } } if (!check) cout << -1 << "\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...