Submission #880210

#TimeUsernameProblemLanguageResultExecution timeMemory
880210cpptowinBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1029 ms328508 KiB
#include<bits/stdc++.h> #define fo(i,d,c) for(int i=d;i<=c;i++) #define fod(i,c,d) for(int i=c;i>=d;i--) #define maxn 200010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout<<"\n"; //#define int long long #define inf 1000000000 #define pii pair<int,int> #define vii vector<pii> #define lb(x) x&-x #define bit(i,j) ((i>>j)&1) #define offbit(i,j) (i^(1<<j)) #define onbit(i,j) (i|(1<<j)) #define vi vector<int> template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } using namespace std; int n,m,q; const int nsqrt = 250; vi ke[maxn]; vii d[maxn]; int dist[maxn]; bool ok[maxn]; bool vis[maxn]; int from[maxn]; int val[maxn]; main() { #define name "TASK" if(fopen(name".inp","r")) { freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> q; fo(i,1,m) { int u,v; cin >> u >> v; ke[v].pb(u); } fo(u,1,n) { vi now; for(int v : ke[u]) { for(auto [z,t] : d[v]) { if(from[z] == u) val[z] = max(val[z],t + 1); else { from[z] = u; val[z] = t + 1; now.pb(z); } } } d[u].pb(u,0); for(int it : now) d[u].pb(it,val[it]); sort(d[u].begin(),d[u].end(),[](pii a,pii b) { return a.se > b.se or (a.se == b.se and a.fi > b.fi); }); if(d[u].size() > nsqrt) d[u].erase(d[u].begin() + nsqrt,d[u].end()); } while(q--) { int ans = -1; int t,s; cin >> t >> s; vi bad(s); for(int &it : bad) { cin >> it; ok[it] = 1; } if(s > nsqrt) { fod(u,n,1) dist[u] = -1; dist[t] = 0; fod(u,t,1) if(dist[u] >= 0) { if(!ok[u]) ans = max(ans,dist[u]); for(int v : ke[u]) { dist[v] = max(dist[v],dist[u] + 1); } } } else { for(auto [i,j] : d[t]) { if(!ok[i]) { ans = j; break; } } } for(int it : bad) ok[it] = 0; cout << ans;en; } }

Compilation message (stderr)

bitaro.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main()
      | ^~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...