제출 #1148338

#제출 시각아이디문제언어결과실행 시간메모리
1148338akamizaneBitaro’s Party (JOI18_bitaro)C++20
0 / 100
5 ms6728 KiB
#include<bits/stdc++.h> using namespace std; #define debug(...) 40 using ll = long long; using pii = pair<long long, long long>; using db = long double; #define int long long #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FOD(i, a, b) for (int i = (a); i >= (b); i--) #define REP(i, n) for (int i = 0; i < (n); i++) template <class T1, class T2>bool chmax(T1 &a, T2 b){return a < b ? a = b, 1 : 0;} template <class T1, class T2>bool chmin(T1 &a, T2 b){return a > b ? a = b, 1 : 0;} const int maxn = 1e5 + 5; const int mod = 998244353; const ll inf = 1e18; vector<int> ad[maxn]; vector<array<int, 2>> node[maxn]; int dis[maxn], vis[maxn], bad[maxn], dp[maxn]; void solve(){ int n, m, q; cin >> n >> m >> q; REP(i, m){ int u, v; cin >> u >> v; ad[v].pb(u); } const int block = 100; vector<int> cur; for (int i = 1; i <= n; i++, cur.clear()){ for (auto j : ad[i]){ for (auto [w, u] : node[j]){ if (vis[u] == i) chmax(dis[u], w + 1); else vis[u] = i, dis[u] = w + 1, cur.pb(u); } } for (auto u : cur) node[i].pb({dis[u], u}); node[i].pb({0, i}); sort(node[i].rbegin(), node[i].rend()); while(node[i].size() > block) node[i].pop_back(); } FOR(cnt, 1, q){ int t, k, x, ans = -1; cin >> t >> k; REP(i, k){ int x; cin >> x; bad[x] = cnt; } if (k < block){ for (auto [w, u] : node[t]){ if (bad[u] != cnt){ ans = w; break; } } } else{ memset(dp, -1, sizeof dp); for (int i = 1; i <= t; i++){ if (bad[i] != cnt) dp[i] = 0; for (auto j : ad[i]){ if (dp[j] != -1) chmax(dp[j], dp[i] + 1); } } ans = dp[t]; } cout << ans << "\n"; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tests = 1; // cin >> tests; for (int _ = 1; _ <= tests; _++){ solve(); cout << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...