Submission #719365

#TimeUsernameProblemLanguageResultExecution timeMemory
719365n0sk1llPolitical Development (BOI17_politicaldevelopment)C++14
39 / 100
463 ms31312 KiB
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0) #define mp make_pair #define xx first #define yy second #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define all(x) x.begin(),x.end() #define ff(i,a,b) for (int i = a; i < b; i++) #define fff(i,a,b) for (int i = a; i <= b; i++) #define bff(i,a,b) for (int i = b-1; i >= a; i--) #define bfff(i,a,b) for (int i = b; i >= a; i--) using namespace std; long double typedef ld; unsigned int typedef ui; long long int typedef li; pair<int,int> typedef pii; pair<li,li> typedef pli; pair<ld,ld> typedef pld; vector<vector<int>> typedef graph; unsigned long long int typedef ull; //const int mod = 998244353; const int mod = 1000000007; //Note to self: Check for overflow struct find_clique { int g[102]; //graph by bitmask int dp1[3500]; //first half int pc[3500]; //precalced int dp2[3500]; //second half void clear(int n) { ff(i,0,n) g[i]=0; ff(i,0,(1<<n)) dp1[i]=0; ff(i,0,(1<<n)) dp2[i]=0; } void add(int u, int v) { g[u]|=(1<<v); g[v]|=(1<<u); } /*int calc(int n) { int fh=n/2,sh=(n+1)/2,fb=(1<<fh)-1,sb=(1<<sh)-1; ff(i,0,(1<<sh)) pc[i]=__builtin_popcount(i); ff(mask,1,(1<<fh)) ff(j,0,fh) if (mask&(1<<j)) { dp1[mask]=max(dp1[mask],dp1[mask&g[j]]+1); } ff(mask,1,(1<<sh)) ff(j,0,sh) if (mask&(1<<j)) { dp2[mask]=max(dp2[mask],dp2[mask&(g[j]>>fh)]+1); } int ans=0; ff(mask,0,(1<<sh)) if (dp2[mask]==pc[mask]) { int span=0; ff(j,0,sh) if (mask&(1<<j)) span|=(g[j]&fb); ans=max(ans,pc[mask]+dp1[span]); } return ans; }*/ int calc(int n) { int ans=0; ff(mask,0,(1<<n)) { bool dobar=true; ff(j,0,n) if (((g[j]|(1<<j))&mask)!=mask) dobar=false; if (dobar) ans=max(ans,__builtin_popcount(mask)); } return ans; } } ok; set<pii> pq; set<int> idemo[100005]; int main() { FAST; int n,k; cin>>n>>k; ff(i,0,n) { int d; cin>>d; while (d--) { int x; cin>>x; idemo[i].insert(x); idemo[x].insert(i); } } ff(i,0,n) pq.insert({(int)idemo[i].size(),i}); int ans=0; while (!pq.empty()) { int p=pq.begin()->yy; vector<int> cvors; cvors.pb(p); for (auto it : idemo[p]) cvors.pb(it); /*cout<<"consider: "; for (auto it : cvors) cout<<it<<" "; cout<<endl;*/ ok.clear((int)cvors.size()); ff(i,0,(int)cvors.size()) ff(j,i+1,(int)cvors.size()) if (idemo[cvors[i]].count(cvors[j])) ok.add(i,j); ans=max(ans,ok.calc((int)cvors.size())); for (auto it : idemo[p]) pq.erase({(int)idemo[it].size(),it}),idemo[it].erase(p),pq.insert({(int)idemo[it].size(),it}); pq.erase({(int)idemo[p].size(),p}); } cout<<ans<<"\n"; } //Note to self: Check for overflow /* 5 3 2 1 2 3 0 2 3 3 0 1 4 2 1 4 2 2 3 */
#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...