Submission #928334

#TimeUsernameProblemLanguageResultExecution timeMemory
928334AiperiiiBitaro’s Party (JOI18_bitaro)C++14
7 / 100
1269 ms524288 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define all(x) x.begin(),x.end() #define pb push_back using namespace std; const int N=1e5+5; vector <pair <int,int> > cct[N]; vector <int> g[N]; signed main(){ int n,m,q; cin>>n>>m>>q; for(int i=0;i<m;i++){ int u,v; cin>>u>>v; g[v].pb(u); } int sq=400; vector <int> d(n+1),ld(n+1),can; for(int i=1;i<=n;i++){ d[i]=0; can.pb(i); for(auto edg : g[i]){ for(auto x : cct[edg]){ if(ld[x.ss]==i){ d[x.ss]=max(d[x.ss],x.ff+1); } else{ d[x.ss]=x.ff+1; ld[x.ss]=i; can.pb(x.ss); } } } sort(all(can),[&](int a, int b){return d[a]>d[b];}); for(int j=max(0ll,(int)can.size()-sq);j<can.size();j++){ int x=can[j]; cct[i].pb({d[x],x}); } can.clear(); } vector <int> no(n+1),dp(n+1); while(q--){ int t,s; cin>>t>>s; vector <int> a(s); for(int i=0;i<s;i++){ cin>>a[i]; no[a[i]]=1; dp[a[i]]=-1e9; } int ans=-1; if(s<sq){ for(auto x : cct[t]){ if(!no[x.ss]){ ans=x.ff; break; } } } else{ for(int i=1;i<=t;i++){ for(auto edg : g[i]){ dp[i]=max(dp[i],dp[edg]+1); } } ans=max(ans,dp[t]); for(int i=1;i<=t;i++){ dp[i]=0; } } cout<<ans<<"\n"; for(int i=0;i<s;i++){ no[a[i]]=0; dp[a[i]]=0; } } } /* */

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:38:48: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int j=max(0ll,(int)can.size()-sq);j<can.size();j++){
      |                                               ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...