Submission #707424

#TimeUsernameProblemLanguageResultExecution timeMemory
707424EthanKim8683Bitaro’s Party (JOI18_bitaro)C++17
14 / 100
2089 ms320708 KiB
#include<bits/stdc++.h> using namespace std; using I=int; const I N=100000; const I Q=100000; const I MIN=-1e9; vector<I>adjs1[N],adjs2[N]; set<I>bsys[Q]; vector<I>inds[N]; set<I>viss; vector<pair<I,I>>pres[N],tops[N]; I ress[Q]; I diss[N]; I tims[N]; I tim=1; I dfs(I a,I i){ if(tims[a]==tim)return diss[a]; tims[a]=tim,diss[a]=bsys[i].count(a)?MIN:0; for(auto b:adjs2[a])if(dfs(b,i)!=MIN)diss[a]=max(diss[a],diss[b]+1); return diss[a]; } I main(){ cin.tie(0)->sync_with_stdio(0); I n,m,q;cin>>n>>m>>q; for(I i=0;i<m;i++){ I s,e;cin>>s>>e,s--,e--; adjs1[s].push_back(e); adjs2[e].push_back(s); } fill_n(ress,q,MIN); for(I i=0;i<q;i++){ I t,y;cin>>t>>y,t--; inds[t].push_back(i); for(I j=0;j<y;j++){ I c;cin>>c,c--; bsys[i].insert(c); } } I siz=sqrt(n/log2(n)); for(I i=0;i<n;i++){ pres[i].push_back({0,i}); sort(pres[i].begin(),pres[i].end()); viss.clear(); for(I j=0;j<pres[i].size()&&tops[i].size()<siz;j++){ auto[dis,k]=pres[i][j]; if(viss.count(k))continue; viss.insert(k),tops[i].push_back({dis,k}); } for(auto j:inds[i]){ for(auto[dis,k]:tops[i])if(!bsys[j].count(k)){ress[j]=-dis;break;} if(ress[j]!=MIN)continue; if(bsys[j].size()<siz)continue; ress[j]=dfs(i,j),tim++; } for(auto j:adjs1[i])for(auto[dis,k]:tops[i])pres[j].push_back({dis-1,k}); pres[i].clear(),tops[i].clear(); } for(I i=0;i<q;i++)printf("%i\n",ress[i]==MIN?-1:ress[i]); }

Compilation message (stderr)

bitaro.cpp: In function 'I main()':
bitaro.cpp:44:16: warning: comparison of integer expressions of different signedness: 'I' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(I j=0;j<pres[i].size()&&tops[i].size()<siz;j++){
      |               ~^~~~~~~~~~~~~~~
bitaro.cpp:44:47: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'I' {aka 'int'} [-Wsign-compare]
   44 |     for(I j=0;j<pres[i].size()&&tops[i].size()<siz;j++){
      |                                 ~~~~~~~~~~~~~~^~~~
bitaro.cpp:52:24: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'I' {aka 'int'} [-Wsign-compare]
   52 |       if(bsys[j].size()<siz)continue;
      |          ~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...