제출 #500105

#제출 시각아이디문제언어결과실행 시간메모리
500105kamalsharmaa9Bitaro’s Party (JOI18_bitaro)C++14
0 / 100
13 ms20392 KiB
#include<bits/stdc++.h> using namespace std; #define N 100050 #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int B = 150; int not_taken[N]; vector<int>gr[N]; vector<int>grr[N]; int dp[N]; set<pii, greater<pii>>dist[N]; int32_t main() { c_p_c(); int n, m, q; cin >> n >> m >> q; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; gr[a].pb(b); grr[b].pb(a); } ///// precomputation for (int i = 1; i <= n; i++) { int node = i; for (auto child : grr[node]) { for (auto j : dist[child]) { dist[node].insert({j.ff + 1, j.ss}); } } dist[node].insert({0, node}); while (dist[node].size() >= B) dist[node].erase(dist[node].end()); } while (q--) { int p, q; cin >> p >> q; vector<int>not_take; for (int i = 1; i <= q; i++) { int r; cin >> r; not_take.pb(r); not_taken[r] = 1; } /////////////////////////// if (q <= B) { int ans = -1; for (auto i : dist[p]) { if (not_taken[i.second]) continue; ans = i.first; break; } cout << ans << '\n'; } else { for (int i = 1; i <= p; i++) { dp[i] = 0; } for (int i = 1; i <= p - 1; i++) { if (not_taken[i] && dp[i] == 0) continue; for (auto child : gr[i]) { dp[child] = max(dp[child], dp[i] + 1); } } cout << dp[p] << '\n'; } for (auto i : not_take) not_taken[i] = 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...