Submission #1054304

#TimeUsernameProblemLanguageResultExecution timeMemory
1054304manhlinh1501Bitaro’s Party (JOI18_bitaro)C++17
100 / 100
709 ms219940 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using i64 = long long; const int MAXN = 2e5 + 5; const int BLOCK_SIZE = 200; #define ALL(a) (a).begin(), (a).end() int N, M, Q; vector<int> adj[MAXN]; bool is_deleted[MAXN]; vector<pii> dp[MAXN]; int dist[MAXN]; bool f[MAXN]; vector<pii> merge_vector(vector<pii> &x, vector<pii> &y) { vector<pii> z; int px = 0, py = 0; while((int)z.size() <= BLOCK_SIZE && px + py < (int)x.size() + (int)y.size()) { while(px < (int)x.size() && f[x[px].second]) { ++px; } while(py < (int)y.size() && f[y[py].second]) { ++py; } if(px < (int)x.size() && (py == (int)y.size() || x[px].first > y[py].first + 1)) { f[x[px].second] = 1; z.push_back(x[px++]); } else if(py < (int)y.size()) { f[y[py].second] = 1; z.push_back({y[py].first + 1, y[py++].second}); } } for(auto [D, x] : z) { f[x] = 0; } return z; } signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M >> Q; for(int i = 1; i <= M; i++) { int u, v; cin >> u >> v; adj[v].emplace_back(u); } for(int u = 1; u <= N; u++) { dp[u].emplace_back(0, u); for(int v : adj[u]) dp[u] = merge_vector(dp[u], dp[v]); } while(Q--) { int u; cin >> u; int sz; cin >> sz; vector<int> a(sz, 0); for(int &x : a) cin >> x; for(int x : a) is_deleted[x] = true; if(a.size() >= BLOCK_SIZE) { for(int u = 1; u <= N; u ++) { dist[u] = 0; } for(int x : a) { dist[x] = -1e9; } for(int u = 1; u <= N; u ++) { for(int v : adj[u]) { dist[u] = max(dist[u], dist[v] + 1); } } cout << max(-1, dist[u]) << endl; } else { int ans = -1; for(auto [x, y] : dp[u]) { if(is_deleted[y] == false) ans = max(ans, x); } cout << ans << "\n"; } for(int x : a) is_deleted[x] = false; } return (0 ^ 0); }

Compilation message (stderr)

bitaro.cpp: In function 'std::vector<std::pair<int, int> > merge_vector(std::vector<std::pair<int, int> >&, std::vector<std::pair<int, int> >&)':
bitaro.cpp:30:47: warning: operation on 'py' may be undefined [-Wsequence-point]
   30 |             z.push_back({y[py].first + 1, y[py++].second});
      |                                             ~~^~
bitaro.cpp: In function 'int main()':
bitaro.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...