Submission #137914

#TimeUsernameProblemLanguageResultExecution timeMemory
137914UtahaParachute rings (IOI12_rings)C++14
100 / 100
2397 ms127180 KiB
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ld,ld> pdd; #define IOS ios_base::sync_with_stdio(0); cin.tie(0) #define ALL(a) a.begin(),a.end() #define SZ(a) ((int)a.size()) #define F first #define S second #define REP(i,n) for(int i=0;i<((int)n);i++) #define pb emplace_back #define MP(a,b) make_pair(a,b) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define EL cout<<'\n' template<typename T1,typename T2> ostream& operator<<(ostream& out,pair<T1,T2> P){ out<<'('<<P.F<<','<<P.S<<')'; return out; } template<typename T> ostream& operator<<(ostream& out,vector<T> V){ REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":""); return out; } #define version 20190726 //}}} const ll maxn=1000005; const ll maxlg=20; const ll INF64=1e18; const int INF=0x3f3f3f3f; const ll MOD=ll(1e9+7); const ld PI=acos(-1); const ld eps=1e-9; //const ll p=880301; //const ll P=31; ll mypow(ll a,ll b){ ll res=1LL; while(b){ if(b&1) res=res*a%MOD; a=a*a%MOD; b>>=1; } return res; } struct DSU{ int dsu[maxn]; int sz[maxn]; DSU(){} void init(int n){ REP(i,n) dsu[i]=i,sz[i]=1; } int find(int u){ if(dsu[u]==u) return u; return dsu[u]=find(dsu[u]); } void mrg(int u,int v){ u=find(u); v=find(v); if(u==v) return; if(sz[u]<sz[v]) swap(u,v); dsu[v]=u; sz[u]+=sz[v]; } }; struct checker{ int dsu[maxn]; int sz[maxn]; int deg[maxn]; bool valid=1; checker(){} void init(int n){ REP(i,n) dsu[i]=i,sz[i]=1; } int find(int u){ if(dsu[u]==u) return u; return dsu[u]=find(dsu[u]); } void mrg(int u,int v){ deg[u]++,deg[v]++; if(deg[u]==3||deg[v]==3) valid=0; u=find(u); v=find(v); if(u==v){ valid=0; return; } if(sz[u]<sz[v]) swap(u,v); dsu[v]=u; sz[u]+=sz[v]; } }; int n; bool stage=0; int deg[maxn]; vector<int> edge[maxn]; vector<int> p; DSU orig; int ring=0; int ringsz=-1; checker nw[5]; void Init(int N){ n=N; orig.init(N); } void Link(int A, int B) { deg[A]++; deg[B]++; edge[A].pb(B); edge[B].pb(A); bool f=0; if((!stage)&&(deg[A]==3)){ f=1; stage=1; p.pb(A); for(int i:edge[A]) p.pb(i); REP(i,SZ(p)){ nw[i].init(n); REP(j,n) for(int k:edge[j]){ if(j<k&&j!=p[i]&&k!=p[i]){ nw[i].mrg(j,k); } } } } if((!stage)&&(deg[B]==3)){ f=1; stage=1; p.pb(B); for(int i:edge[B]) p.pb(i); REP(i,SZ(p)){ nw[i].init(n); REP(j,n) for(int k:edge[j]){ if(j<k&&j!=p[i]&&k!=p[i]){ nw[i].mrg(j,k); } } } } if(stage==0){ if(orig.find(A)==orig.find(B)){ ring++; if(ring==1){ ringsz=orig.sz[orig.find(A)]; } } else{ orig.mrg(A,B); } } else{ if(f); else{ REP(i,SZ(p)){ if(p[i]!=A&&p[i]!=B){ nw[i].mrg(A,B); } } } } } int CountCritical() { if(stage){ int ans=0; REP(i,4) ans+=nw[i].valid; return ans; } else{ if(ring>=2){ return 0; } if(ring==1) return ringsz; return n; } }
#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...