Submission #1150464

#TimeUsernameProblemLanguageResultExecution timeMemory
1150464minggaBitaro’s Party (JOI18_bitaro)C++20
100 / 100
1029 ms410648 KiB
#include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) // #define int long long const int mod = 1e9 + 7; const int inf = 2e9; const int N = 1e5 + 7; vector<int> g[N]; int n, m, q; const int B = 330; vector<pair<int, int>> path[N]; bool vis[N], del[N]; int dp[N]; signed main() { cin.tie(0) -> sync_with_stdio(0); #define task "" if(fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } cin >> n >> m >> q; for(int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[v].pb(u); } for(int u = 1; u <= n; u++) { for(int v : g[u]) { int i = 0, j = 0; vector<pair<int, int>> nxt; vector<int> sus; while(1) { if(i < sz(path[u]) and (j >= sz(path[v]) or path[u][i].se >= path[v][j].se + 1)) { assert(i < sz(path[u])); if(!vis[path[u][i].fi]) { int x = path[u][i].fi, w = path[u][i].se; nxt.pb({x, w}); vis[x] = 1; sus.pb(x); } i++; } else if(j < sz(path[v]) and (i >= sz(path[u]) or path[v][j].se + 1 > path[u][i].se)) { if(!vis[path[v][j].fi]) { int x = path[v][j].fi, w = path[v][j].se; nxt.pb({x, w + 1}); vis[x] = 1; sus.pb(x); } j++; } if(i >= sz(path[u]) and j >= sz(path[v])) break; if(sz(nxt) >= B) break; } swap(path[u], nxt); for(int x : sus) vis[x] = 0; } if(sz(path[u]) < B and !vis[u]) path[u].pb({u, 0}); } // for(int i = 1; i <= n; i++) { // cout << "PATH " << i << ln; // for(auto x : path[i]) { // cout << x.fi << ' ' << x.se << ln; // } // } for(int i = 1; i <= q; i++) { int t, y; cin >> t >> y; vector<int> sus; for(int j = 1; j <= y; j++) { int x; cin >> x; del[x] = 1; sus.pb(x); } if(y >= B) { memset(dp, -0x3f, sizeof dp); for(int i = 1; i <= t; i++) { if(!del[i]) dp[i] = 0; for(int v : g[i]) { dp[i] = max(dp[i], dp[v] + 1); } } if(dp[t] < 0) dp[t] = -1; cout << dp[t] << ln; } else { int ans = -1; for(auto x : path[t]) { if(!del[x.fi]) { ans = x.se; break; } } cout << ans << ln; } for(int x : sus) del[x] = 0; } cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(task ".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(task ".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...