제출 #1258384

#제출 시각아이디문제언어결과실행 시간메모리
1258384ssitaramBitaro’s Party (JOI18_bitaro)C++20
100 / 100
1590 ms310044 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, q; cin >> n >> m >> q; int bl = 220; vector<vector<int>> to(n), into(n); for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; to[--a].push_back(--b); into[b].push_back(a); } vector<vector<pair<int, int>>> best(n); vector<int> from(n, -1); for (int i = 0; i < n; ++i) { from[i] = 0; vector<int> idxs = {i}; for (int j : into[i]) { for (pair<int, int> k : best[j]) { if (from[k.second] == -1) { from[k.second] = k.first + 1; idxs.push_back(k.second); } else { from[k.second] = max(from[k.second], k.first + 1); } } } for (int j : idxs) { best[i].push_back({from[j], j}); } sort(best[i].rbegin(), best[i].rend()); while (best[i].size() > bl) best[i].pop_back(); for (int j : idxs) { from[j] = -1; } } vector<bool> nouse(n); vector<int> mx(n); vector<int> c(n); while (q--) { int t, y; cin >> t >> y; for (int i = 0; i < y; ++i) { cin >> c[i]; --c[i]; nouse[c[i]] = true; } --t; if (y >= bl) { int ans = -1; for (int j = t; j >= 0; --j) { mx[j] = (j == t ? 0 : -1); for (int k : to[j]) { if (k <= t && mx[k] != -1) mx[j] = max(mx[j], mx[k] + 1); } if (!nouse[j]) ans = max(ans, mx[j]); } cout << ans << '\n'; } else { auto it = best[t].begin(); while (it != best[t].end() && nouse[it->second]) { ++it; } if (it == best[t].end()) { cout << "-1\n"; } else { cout << it->first << '\n'; } } for (int i = 0; i < y; ++i) { nouse[c[i]] = false; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...