Submission #829348

#TimeUsernameProblemLanguageResultExecution timeMemory
829348Darren0724Political Development (BOI17_politicaldevelopment)C++17
100 / 100
1018 ms28924 KiB
#include<bits/stdc++.h> using namespace std; const int N=50005; vector<int> adj[N],adj1[N]; vector<int> deg(N); set<pair<int,int>> s; vector<int> active(N,1); int calc(int p){ int sz=adj[p].size(); //cout<<sz<<endl; int g[sz]{}; for(int i=0;i<sz;i++){ for(int j=0;j<sz;j++){ if(i==j||s.find({adj[p][i],adj[p][j]})!=s.end()){ g[i]|=1<<j; } } } int ans=0; for(int i=1;i<1<<sz;i++){ int p=i; int cnt=0; for(int j=0;j<sz;j++){ if(i&(1<<j)){ p&=g[j]; cnt++; } } if(p==i){ ans=max(ans,cnt); } } return ans; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n,k;cin>>n>>k; for(int i=0;i<n;i++){ cin>>deg[i]; adj1[i].resize(deg[i]+1); adj1[i][0]=i; for(int j=1;j<=deg[i];j++){ cin>>adj1[i][j]; s.insert({i,adj1[i][j]}); s.insert({adj1[i][j],i}); } } queue<int> q; for(int i=0;i<n;i++){ if(deg[i]<=k){ q.push(i); } } int ans=0; while(q.size()){ int p=q.front(); q.pop(); for(int j:adj1[p]){ if(active[j]){ adj[p].push_back(j); } deg[j]--; if(deg[j]==k){ q.push(j); } } ans=max(ans,calc(p)); active[p]=0; } cout<<ans<<endl; return 0; }
#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...