Submission #890219

#TimeUsernameProblemLanguageResultExecution timeMemory
890219LeVanThucBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1098 ms286192 KiB
#include<bits/stdc++.h> using namespace std; #define ll int #define fi first #define se second #define p(x,y) pair<ll,ll>(x,y) #define BIT(i,x) ((x>>i)&1) #define MASK(x) (1<<x) #define ld long double #define __builtin_popcount __builtin_popcountll #define pll pair<ll,ll> template<class T1,class T2> bool maximize(T1 &x,T2 y) { if(x<y) { x=y; return 1; } return 0; } template<class T1,class T2> bool minimize(T1 &x,T2 y) { if(y<x) { x=y; return 1; } return 0; } const ll M=1e9+7; template <class T1,class T2> void add(T1 &x,T2 y) { x+=y; if(x>=M) x-=M; } template <class T1,class T2> void sub(T1 &x, T2 y) { x-=y; if(x<0) x+=M; } void online() { std::ios_base::sync_with_stdio(0); cin.tie(0); #ifdef thuc freopen("input.inp","r",stdin); freopen("output.out","w",stdout); #else #endif // thuc } const ll N=2e5+10; ll vs[N],f[N],ban[N],n,m,q,src; vector<ll> gr[N],rgr[N]; ll solve1(ll u) { if(vs[u]) return f[u]; vs[u]=1; f[u]=-1e9; if(u==src) return f[u]=0; for(auto v:gr[u]) { maximize(f[u],solve1(v)+1); maximize(f[u],solve1(v)+1); } return f[u]; } ll tr(ll u,ll y) { vector<ll> vt; for(int i=1; i<=y; i++) { ll x; cin>>x; ban[x]=1; vt.push_back(x); } memset(f,-1,sizeof f); for(int i=1;i<=u;i++) { if(!ban[i]) f[i]=0; for(auto v:rgr[i]) if(f[v]!=-1) maximize(f[i],f[v]+1); } for(auto v:vt) ban[v]=0; return f[u]; } bool sub2() { ll t,y; cin>>t>>y; cout<<tr(t,y); return 0; } map<ll,ll> Map[N]; vector<pll> bt[N]; ll tr2(ll u,ll y) { vector<ll> vt; for(int i=1; i<=y; i++) { ll x; cin>>x; vt.push_back(x); ban[x]=1; } ll ans=-1; for(int i=0; i<bt[u].size(); i++) { if(!ban[bt[u][i].se]) { ans=bt[u][i].fi; break; } } for(auto v:vt) ban[v]=0; return ans; } ll dis[N]; bool sub3() { for(int i=1;i<=n;i++) { vector<ll> temp; for(auto v:rgr[i]) for(auto [vl,x]:bt[v]) { if(vs[x]==i) maximize(dis[x],vl); else vs[x]=i,dis[x]=vl,temp.push_back(x); } for(auto v:temp) { bt[i].push_back(p(dis[v]+1,v)); } bt[i].push_back(p(0,i)); sort(bt[i].begin(),bt[i].end(),greater<pll>()); while(bt[i].size()>200) bt[i].pop_back(); } // for(int i=1;i<=n;i++) // { // for(auto [x,y]:bt[i]) cout<<x<<','<<y<<' '; // cout<<'\n'; // } for(int i=1; i<=q; i++) { ll t,y; cin>>t>>y; if(y>=200) { cout<<tr(t,y)<<'\n'; } else cout<<tr2(t,y)<<'\n'; } return 0; } int main() { online(); cin>>n>>m>>q; for(int i=1; i<=m; i++) { ll u,v; cin>>u>>v; if(u>v) swap(u,v); gr[u].push_back(v); rgr[v].push_back(u); } // if(q==1) return sub2(); return sub3(); }

Compilation message (stderr)

bitaro.cpp: In function 'int tr2(int, int)':
bitaro.cpp:110:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for(int i=0; i<bt[u].size(); i++)
      |                  ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...