Submission #239317

#TimeUsernameProblemLanguageResultExecution timeMemory
239317dsjongPolitical Development (BOI17_politicaldevelopment)C++14
100 / 100
2850 ms66200 KiB
#include <bits/stdc++.h> using namespace std; int sz[100005]; bool good[2000]; vector<int>adj[100005]; map<pair<int, int>, int> mp; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin>>n>>k; for(int i=0;i<n;i++){ int d; cin>>d; for(int j=0;j<d;j++){ int x; cin>>x; adj[i].push_back(x); mp[{i, x}]=true; } sz[i]=d; } int ans=1; for(int t=0;t<n;t++){ int mini=INT_MAX, idx; for(int i=0;i<n;i++){ if(sz[i]<mini){ mini=sz[i]; idx=i; } } // cout<<idx<<endl; vector<int>v; for(int i:adj[idx]){ if(sz[i]<=n) v.push_back(i); } int m=v.size(); good[0]=true; for(int i=1;i<(1<<m);i++){ int lg=log2(i); int x=i-(1<<lg); if(good[x]){ bool b=true; for(int j=0;j<m;j++){ if((1<<j)&x) if(j!=lg) b&=mp[{v[j], v[lg]}]; } good[i]=b; } else good[i]=false; if(good[i]){ int cnt=0; for(int j=0;j<m;j++){ if((1<<j)&i) cnt++; } ans=max(ans, cnt+1); } } sz[idx]=INT_MAX; for(int i:adj[idx]) sz[i]--; } cout<<ans; }

Compilation message (stderr)

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:60:16: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
         sz[idx]=INT_MAX;
                ^
#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...