# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
186954 | nicolaalexandra | Political Development (BOI17_politicaldevelopment) | C++14 | 443 ms | 29080 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DIM 50010
using namespace std;
priority_queue <pair<int,int>, vector <pair<int,int> >, greater<pair<int,int> > > H;
set <int> L[DIM];
int n,k,i,j,sol,el,nod;
int v[DIM],x[DIM],viz[DIM],f[DIM],g[DIM],mask[DIM];
int verif (int x, int y){
if (L[x].find(y) != L[x].end())
return 1;
return 0;
}
void get_max_clique (int nod){
el = 0;
v[++el] = nod;
for (auto vecin:L[nod])
v[++el] = vecin;
// cout<<el<<endl;
for (int i=1;i<=el;i++)
mask[i] = 0;
for (int i=1;i<=el;i++)
for (int j=1;j<=el;j++){
if (i == j){
mask[i] |= (1<<(i-1));
continue;
}
if (verif(v[i],v[j]))
mask[i] |= (1<<(j-1));
}
int val = (1<<el)-1;
for (int i=0;i<=val;i++){
int ok = 0;
for (int bit=0;bit<el;bit++){
if (!(i&(1<<bit))) /// nu face parte din masca
continue;
if ((mask[bit+1]&i) != i){ /// nu se potrivesc
ok = 1;
break;
}
}
if (!ok)
sol = max (sol,__builtin_popcount(i));
}
}
int main (){
FILE *fin = stdin;
FILE *fout = stdout;
fscanf (fin,"%d%d",&n,&k);
for (i=1;i<=n;++i){
fscanf (fin,"%d",&g[i]);
for (j=1;j<=g[i];++j){
fscanf (fin,"%d",&nod);
L[i].insert(nod+1);
}
H.push (make_pair(g[i],i));
}
while (!H.empty()){
int nod = H.top().second;
int grad = H.top().first;
H.pop();
if (grad != g[nod]) /// inseamna ca nu e ala cu gradul minim
continue;
/// vreau sa gasesc clica maxima din care poate face parte nod
get_max_clique (nod);
viz[nod] = 1;
/// acum il elimin pe nod si toate muchiile
for (auto vecin:L[nod]){
if (viz[vecin])
continue;
/// nu am incercat sa obtin clica de aici deloc
//viz[vecin] = 1;
--g[vecin];
L[vecin].erase(L[vecin].find(nod));
H.push(make_pair(g[vecin],vecin));
}
L[nod].clear();
}
fprintf(fout,"%d",sol);
return 0;
}
/// din nou, nu sunt in stare sa citesc un enunt cum trb
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |