제출 #447898

#제출 시각아이디문제언어결과실행 시간메모리
447898SirCovidThe19thBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1409 ms111280 KiB
#include <bits/stdc++.h> using namespace std; #define v vector #define pii pair<int, int> #define pb push_back #define f first #define s second const int mx = 1e5+5, sq = 110; int n, m, q; vector<int> adj[mx]; v<pii> far[mx]; bool use[mx]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> q; for (int i = 0; i < m; i++){ int a, b; cin >> a >> b; adj[a-1].pb(b-1); } auto merge = [&](v<pii> a, v<pii> b){ v<pii> ret; v<int> vis; int x = 0, y = 0, szA = a.size(), szB = b.size(); auto ins = [&](v<pii> &cur, int &i){ if (!use[cur[i].f]) ret.pb(cur[i]); use[cur[i].f] = 1; vis.pb(cur[i].f); i++; };while (ret.size() < sq and (x < szA or y < szB)){ if (x < szA and (y >= szB or a[x].s+1 > b[y].s)) a[x].s++, ins(a, x); else ins(b, y); }for (auto i : vis){ use[i] = 0; } return ret; };for (int i = 0; i < n; i++) far[i].pb({i, 0}); for (int i = 0; i < n; i++) for (int j : adj[i]) far[j] = merge(far[i], far[j]); while (q--){ int t, y; cin >> t >> y; t--; int C[y], ans = -1; v<int> vis; for (int &i : C) cin >> i, i--, use[i] = 1, vis.pb(i); if (y < sq){ for (auto i : far[t]) if (!use[i.f]){ ans = i.s; break; } } else{ int dp[t+1]; memset(dp, -1, sizeof(dp)); for (int i = 0; i <= t; i++){ if (!use[i]) dp[i] = max(dp[i], 0); for (int j : adj[i]) if (j <= t) dp[j] = max(dp[j], (dp[i] == -1) ? dp[i] : dp[i]+1); }ans = dp[t]; }for (auto i : vis){ use[i] = 0; } cout<<ans<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...