Submission #1012122

#TimeUsernameProblemLanguageResultExecution timeMemory
1012122amirhoseinfar1385Parachute rings (IOI12_rings)C++17
52 / 100
809 ms262144 KiB
#include<bits/stdc++.h> //#include "rings.h" #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") using namespace std; const int maxn=1000000+10; vector<int>cand; int n; struct gr{ pair<int,int>mx; int par[maxn],sz[maxn],dordare,m,c,moalefedordar; vector<int>adjs[maxn]; gr(){ for(int i=0;i<maxn;i++){ par[i]=i; sz[i]=1; } mx=make_pair(0,-1); m=0; dordare=moalefedordar=c=m=0; } void con(int u,int v){ m++; //adjs[v].push_back(u); if(adjs[u].size()<=3){ adjs[u].push_back(v); } if(adjs[v].size()<=3){ adjs[v].push_back(u); } mx=max(mx,make_pair((int)adjs[u].size(),u)); mx=max(mx,make_pair((int)adjs[v].size(),v)); if(par[u]==v){ dordare++; moalefedordar=sz[u]; }else{ c--; int pu=par[u],pv=par[v],x=sz[u]+sz[v]; sz[pu]=x; sz[pv]=x; par[pu]=pv; par[pv]=pu; } } }gr[5]; void Init(int N){ //int n=N; n=N; for(int i=0;i<5;i++){ gr[i].c=n; } } vector<pair<int,int>>getalle(){ vector<pair<int,int>>ret; for(int i=0;i<n;i++){ for(auto x:gr[0].adjs[i]){ if(x>i){ ret.push_back(make_pair(i,x)); } } } return ret; } void Link(int A, int B){ int u=A; int v=B; int f=(((gr[0].mx).first>=3)); if(gr[0].mx.first<3){ gr[0].con(u,v); } if((int)cand.size()>0){ for(int i=1;i<=4;i++){ if(gr[i].dordare==1||gr[i].mx.first>=3||u==cand[i-1]||v==cand[i-1]){ continue; } gr[i].con(u,v); } } if(f==0&&(gr[0].mx).first>=3){ int z=(gr[0].mx).second; for(auto x:gr[0].adjs[z]){ cand.push_back(x); } cand.push_back(z); vector<pair<int,int>>v=getalle(); for(int i=0;i<(int)cand.size();i++){ for(auto x:v){ if(gr[i+1].dordare==1||gr[i+1].mx.first>=3||x.first==cand[i]||x.second==cand[i]){ continue; } gr[i+1].con(x.first,x.second); } } } } int CountCritical(){ if((gr[0].mx).first>=3){ int res=0; for(int i=1;i<=4;i++){ if(gr[i].dordare==0&&(gr[i].mx).first<3){ res++; } } return res; } if(gr[0].dordare==0){ return n; } if(gr[0].dordare>=2){ return 0; } return gr[0].moalefedordar; }
#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...