Submission #636768

#TimeUsernameProblemLanguageResultExecution timeMemory
636768BinaryboyBitaro’s Party (JOI18_bitaro)C++14
7 / 100
2070 ms213660 KiB
#include <bits/stdc++.h> using namespace std; const int MAXn = 1e5 + 10, SQ =250 + 10; typedef pair<int, int> pii; vector<int> g[MAXn], revg[MAXn]; int n, m, q; pii dp[MAXn][SQ]; int dp_not_coming[MAXn]; bool in_dp[MAXn]; bool not_coming[MAXn]; void makeDp() { for (int i = 0; i < n; i++) { vector<pii> p_update; p_update.push_back(pii(0, i)); for (int u : revg[i]) { for (int j = 0; j < SQ && dp[u][j].first != -1; j++) { p_update.push_back(pii(dp[u][j].first + 1, dp[u][j].second)); } } sort(p_update.begin(), p_update.end()); reverse(p_update.begin(), p_update.end()); int ind = 0, j = 0; while(j < p_update.size() && ind < SQ) { if (!in_dp[p_update[j].second]) { in_dp[p_update[j].second] = true; dp[i][ind++] = pii(p_update[j]); } j++; } for (int x = 0; x < ind; x++) { in_dp[dp[i][x].second] = false; } } } int get_ans_not_coming(int party_v) { for (int i = 0; i <= party_v; i++) { if (!not_coming[i]) { dp_not_coming[i] = 0; } else { dp_not_coming[i] = -1; } for (int u : revg[i]) { if (dp_not_coming[u] != -1) { dp_not_coming[i] = max(dp_not_coming[u] + 1, dp_not_coming[i]); } } } return dp_not_coming[party_v]; } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> n >> m >> q; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v;u--;v--; g[u].push_back(v); revg[v].push_back(u); } for (int i = 0; i < MAXn; i++) for (int j = 0; j < SQ; j++) dp[i][j] = pii(-1,-1); makeDp(); while(q--) { int party_v, cnt_not_coming; cin >> party_v >> cnt_not_coming; party_v--; vector<int> not_coming_query; for (int i = 0; i < cnt_not_coming; i++) { int v; cin >> v; v--; not_coming_query.push_back(v); not_coming[v] = true; } if (cnt_not_coming < SQ - 1) { for (int i = 0; i < SQ; i++) if(!not_coming[dp[party_v][i].second]) { cout << dp[party_v][i].first << '\n'; break; } } else { cout << get_ans_not_coming(party_v) << '\n'; } for (int v : not_coming_query) { not_coming[v] = false; } } }

Compilation message (stderr)

bitaro.cpp: In function 'void makeDp()':
bitaro.cpp:23:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   while(j < p_update.size() && ind < SQ) {
      |         ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...