Submission #218626

#TimeUsernameProblemLanguageResultExecution timeMemory
218626MKopchevPolitical Development (BOI17_politicaldevelopment)C++14
100 / 100
545 ms28932 KiB
#include<bits/stdc++.h> using namespace std; const int nmax=5e4+42,kmax=20; int n,k; set<int> adj[nmax]; priority_queue< pair<int/*size*/,int/*node*/> > pq; int output; int active[kmax],pointer=0; int bitmasks[nmax]; void solve(int node) { active[0]=node; pointer=1; for(auto k:adj[node]) { active[pointer]=k; pointer++; } for(int i=0;i<pointer;i++) bitmasks[i]=0; for(int i=0;i<pointer;i++) for(int j=0;j<pointer;j++) { if(i==j||adj[active[i]].count(active[j])) bitmasks[i]+=(1<<j); } /* cout<<"active: ";for(int i=0;i<pointer;i++)cout<<active[i]<<" ";cout<<endl; cout<<"masks: ";for(int i=0;i<pointer;i++)cout<<bitmasks[i]<<" ";cout<<endl; */ for(int to_test=0;to_test<(1<<pointer);to_test++) { int in=0; for(int j=0;j<pointer;j++) if((to_test&(1<<j))) { if((bitmasks[j]&to_test)!=to_test)in=-1e9; else in++; } output=max(output,in); } } int main() { scanf("%i%i",&n,&k); for(int i=0;i<n;i++) { int sz,node; scanf("%i",&sz); for(int j=1;j<=sz;j++) { scanf("%i",&node); adj[i].insert(node); adj[node].insert(i); } } for(int i=0;i<n;i++) pq.push({-adj[i].size(),i}); for(int turn=0;turn<n;turn++) { while(adj[pq.top().second].size()!=-pq.top().first)pq.pop();//incorrect size int current=pq.top().second; pq.pop(); //cout<<"current= "<<current<<endl; solve(current); for(auto k:adj[current]) { adj[k].erase(current); pq.push({-adj[k].size(),k}); } adj[current]={}; } printf("%i\n",output); return 0; }

Compilation message (stderr)

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:73:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(adj[pq.top().second].size()!=-pq.top().first)pq.pop();//incorrect size
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
politicaldevelopment.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
politicaldevelopment.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&sz);
         ~~~~~^~~~~~~~~~
politicaldevelopment.cpp:62:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%i",&node);
             ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...