제출 #1126744

#제출 시각아이디문제언어결과실행 시간메모리
1126744Mikael639Bitaro’s Party (JOI18_bitaro)C++20
100 / 100
1022 ms166964 KiB
#include <bits/stdc++.h> #define For(i, a, b) for (int i = (a); i <= (b); ++i) #define ForD(i, a, b) for (int i = (a); i >= (b); --i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define repD(i, n) for (int i = (n) - 1; i >= 0; --i) #define pb push_back #define sz(x) (int)x.size() #define all(v) v.begin(), v.end() #define endl '\n' #define fi first #define se second #define ii pair<int, int> #define vi vector<int> #define vii vector<ii> using namespace std; template <class X, class Y> bool minimize(X &x, Y y){ if (x > y){ x = y; return 1; } return 0; } template <class X, class Y> bool maximize(X &x, Y y){ if (x < y){ x = y; return 1; } return 0; } const int N = 1e5 + 5; const int B = 120; const int INF = 1e9; int n, m, q, busy_pussy[N]; vi g[N]; bool busy[N]; int dp[N]; vii st[N]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; rep(i, m){ int u, v; cin >> u >> v; g[v].pb(u); } For(i, 1, n){ st[i].pb({0, i}); vi from; for (int j: g[i]){ for (auto [d, v]: st[j]){ if (!dp[v]){ from.pb(v); dp[v] = d + 1; } else{ maximize(dp[v], d + 1); } } } for (int v: from) st[i].pb({dp[v], v}), dp[v] = 0; sort(all(st[i]), greater<ii>()); while (sz(st[i]) > B) st[i].pop_back(); } while (q--){ int u, k; cin >> u >> k; int cnt = 0; rep(i, k){ cin >> busy_pussy[i]; if (busy_pussy[i] > u) continue; ++cnt; busy[busy_pussy[i]] = 1; } int res = -1; if (cnt >= B){ For(i, 1, u){ dp[i] = busy[i] ? -INF : 0; for (int j: g[i]){ maximize(dp[i], dp[j] + 1); } } maximize(res, dp[u]); } else{ for (auto [d, v]: st[u]) if (!busy[v]){ res = d; break; } } rep(i, k) busy[busy_pussy[i]] = 0; cout << res << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...