Submission #707847

#TimeUsernameProblemLanguageResultExecution timeMemory
707847ToroTNBitaro’s Party (JOI18_bitaro)C++14
14 / 100
943 ms214220 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define X first #define Y second int n,m,t,u_i,v_i,num,ban[100005],root=sqrt(100000),dp[100005]; int hsh[100005],party,hsh2[100005],ans; vector<int> from[100005]; vector<pair<int,int> > best[100005]; vector<pair<int,int> > merge(vector<pair<int,int> > v1,vector<pair<int,int> > v2) { // printf("v1\n"); // for(int i=0;i<v1.size();i++) // { // printf("%d %d\n",v1[i].X,v1[i].Y); // } // printf("\n"); // printf("v2\n"); // for(int i=0;i<v2.size();i++) // { // printf("%d %d\n",v2[i],v2[i].Y); // } // printf("\n"); vector<pair<int,int> > v; int it1=0,it2=0,it=0; while(1) { if(it==root)break; if(it1==v1.size()&&it2==v2.size())break; if(it1==v1.size()) { if(hsh2[v2[it2].Y]==0) { hsh2[v2[it2].Y]=1; v.pb({v2[it2].X+1,v2[it2].Y}); } ++it2; }else if(it2==v2.size()) { if(hsh2[v1[it1].Y]==0) { hsh2[v1[it1].Y]=1; v.pb(v1[it1]); } ++it1; }else { if(v1[it1].X>v2[it2].X+1) { if(hsh2[v1[it1].Y]==0) { hsh2[v1[it1].Y]=1; v.pb(v1[it1]); } ++it1; }else { if(hsh2[v2[it2].Y]==0) { hsh2[v2[it2].Y]=1; v.pb({v2[it2].X+1,v2[it2].Y}); } ++it2; } } ++it; } for(int i=0;i<v1.size();i++)hsh2[v1[i].Y]=0; for(int i=0;i<v2.size();i++)hsh2[v2[i].Y]=0; /*printf("vvv\n"); for(int i=0;i<v.size();i++) { printf("%d %d\n",v[i].X,v[i].Y); }*/ return v; } int main() { ios_base::sync_with_stdio(0),cin.tie(0); //root=-1; cin >> n >> m >> t; for(int i=1;i<=m;i++) { cin >> u_i >> v_i; from[v_i].pb(u_i); } for(int i=1;i<=n;i++) { //printf("iiiiiiiiiiii=%d\n",i); best[i].pb({0,i}); for(auto node:from[i]) { //printf("node=%d\n",node); best[i]=merge(best[i],best[node]); } } /*for(int i=1;i<=n;i++) { printf("i=%d\n",i); for(int j=0;j<best[i].size();j++) { printf("%d %d\n",best[i][j].X,best[i][j].Y); } }*/ while(t--) { cin >> party >> num; for(int i=1;i<=num;i++) { cin >> ban[i]; hsh[ban[i]]=1; } /*for(int i=1;i<=n;i++) { printf("%d ",hsh[i]); } printf("\n");*/ if(num>root) { for(int i=1;i<=n;i++) { dp[i]=-1e9; if(hsh[i]==0)dp[i]=0; for(auto node:from[i]) { dp[i]=max(dp[i],dp[node]+1); } } if(dp[party]<0) { printf("-1\n"); }else { printf("%d\n",dp[party]); } }else { ans=-1e9; for(int i=0;i<best[party].size();i++) { if(hsh[best[party][i].Y]==0) { ans=max(ans,best[party][i].X); } } if(ans==-1e9) { printf("-1\n"); }else { printf("%d\n",ans); } } for(int i=1;i<=num;i++) { hsh[ban[i]]=0; } } }

Compilation message (stderr)

bitaro.cpp: In function 'std::vector<std::pair<int, int> > merge(std::vector<std::pair<int, int> >, std::vector<std::pair<int, int> >)':
bitaro.cpp:29:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if(it1==v1.size()&&it2==v2.size())break;
      |            ~~~^~~~~~~~~~~
bitaro.cpp:29:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if(it1==v1.size()&&it2==v2.size())break;
      |                            ~~~^~~~~~~~~~~
bitaro.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         if(it1==v1.size())
      |            ~~~^~~~~~~~~~~
bitaro.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         }else if(it2==v2.size())
      |                  ~~~^~~~~~~~~~~
bitaro.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i=0;i<v1.size();i++)hsh2[v1[i].Y]=0;
      |                 ~^~~~~~~~~~
bitaro.cpp:69:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for(int i=0;i<v2.size();i++)hsh2[v2[i].Y]=0;
      |                 ~^~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:139:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |             for(int i=0;i<best[party].size();i++)
      |                         ~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...