Submission #129158

#TimeUsernameProblemLanguageResultExecution timeMemory
129158davitmargPolitical Development (BOI17_politicaldevelopment)C++17
100 / 100
640 ms36728 KiB
/*DavitMarg*/ #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <set> #include <queue> #include <iomanip> #include <stack> #include <cassert> #include <iterator> #include <bitset> #include <fstream> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(),v.end() using namespace std; map<pair<int,int>,bool> edge; int n,k,used[50004],c[(1<<11)+5],ind[50004],s[50004],f[(1<<11)+5],ans=1; vector<int> g[50004]; queue<int> q; int main() { cin>>n>>k; for(int i=0;i<n;i++) { int d,x; cin>>d; for(int j=0;j<d;j++) { scanf("%d",&x); g[i].PB(x); edge[MP(i,x)]=1; } s[i]=g[i].size(); } for(int i=1;i<(1<<k);i++) for(int j=0;j<k;j++) if(((1<<j)&i)) { c[i]++; f[i]=j; } for(int i=0;i<n;i++) if(s[i]<k) q.push(i); while(!q.empty()) { int v=q.front(); q.pop(); if(used[v]) continue; used[v]=1; vector<int> a,mask; for(int i=0;i<g[v].size();i++) { int to=g[v][i]; if(!used[to]) a.PB(to); s[to]--; if(s[to]<k) q.push(to); } mask.resize(a.size(),0); for(int i=0;i<a.size();i++) ind[a[i]]=i; for(int i=0;i<a.size();i++) for(int j=0;j<a.size();j++) { if(i==j || edge.find(MP(a[i],a[j]))==edge.end()) continue; mask[i]+=(1<<j); } vector<bool> dp((1<<a.size())+10); dp[0]=1; for(int m=1;m<(1<<a.size());m++) { int bit=f[m]; int y=m-(1<<bit); if( (mask[bit]&y)==y && dp[y]) { dp[m]=1; ans=max(ans,c[m]+1); } } } cout<<ans<<endl; return 0; } /* 4 2 2 1 4 2 0 2 2 2 4 0 */

Compilation message (stderr)

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:65:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<g[v].size();i++)
                     ~^~~~~~~~~~~~
politicaldevelopment.cpp:75:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<a.size();i++)
               ~^~~~~~~~~
politicaldevelopment.cpp:77:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<a.size();i++)
               ~^~~~~~~~~
politicaldevelopment.cpp:78:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<a.size();j++)
                ~^~~~~~~~~
politicaldevelopment.cpp:38:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&x);
    ~~~~~^~~~~~~~~
#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...