Submission #350953

#TimeUsernameProblemLanguageResultExecution timeMemory
350953juggernautParachute rings (IOI12_rings)C++14
20 / 100
4091 ms26596 KiB
#ifndef EVAL #include"grader.cpp" #endif #include<bits/stdc++.h> using namespace std; vector<int>g[1000005]; bool on[1000005],vis[1000005]; int n,deg[1000005]; int counter[5]; bool flag; int cycle_size,cycle_number,cur_sz,global_answer; void update_counter(int x,int y){ counter[min(x,4)]+=y; } #define DEBUG(x) cout<<#x<<"="<<x<<"\n" void go(int v,int p){ if(on[v])return; cur_sz++; vis[v]=1; for(int to:g[v])if(to!=p){ if(vis[to]){ flag=true; continue; } go(to,v); } } bool check(){ for(int i=0;i<n;i++)vis[i]=0; for(int i=0;i<n;i++){ if(on[i])continue; if(deg[i]>2)return false; if(vis[i])continue; flag=false; go(i,i); if(flag)return false; } return true; } void Init(int N){ n=N; counter[0]=n; global_answer=n; } int get_answer(){ if(counter[4]){ if(counter[4]!=1)return 0; for(int i=0;i<n;i++) if(deg[i]>3){ on[i]=true; for(int to:g[i])deg[i]--,deg[to]--; int ans=check(); for(int to:g[i])deg[i]++,deg[to]++; on[i]=false; return ans; } }else if(counter[3]){ for(int i=0;i<n;i++) if(deg[i]>2){ int ans=0; on[i]=true; for(int to:g[i])deg[i]--,deg[to]--; ans+=check(); for(int to:g[i])deg[i]++,deg[to]++; on[i]=false; for(int to:g[i]){ on[to]=true; for(int to2:g[to])deg[to]--,deg[to2]--; ans+=check(); for(int to2:g[to])deg[to]++,deg[to2]++; on[to]=false; } return ans; } }else{ for(int i=0;i<n;i++)vis[i]=0; cycle_number=cycle_size=0; for(int i=0;i<n;i++){ if(vis[i])continue; flag=false; cur_sz=0; go(i,i); if(flag)cycle_number++,cycle_size=cur_sz; } if(cycle_number==0)return n; else if(cycle_number==1)return cycle_size; else return 0; } } int mx=-1,cnt; void Link(int x,int y){ g[x].push_back(y); g[y].push_back(x); update_counter(deg[x],-1); update_counter(deg[y],-1); deg[x]++; deg[y]++; update_counter(deg[x],+1); update_counter(deg[y],+1); bool need_update=false; if(deg[x]>mx){ mx=deg[x]; cnt=1; need_update=true; }else if(deg[x]==mx)cnt++,need_update=true; if(deg[y]>mx){ mx=deg[y]; cnt=1; need_update=true; }else if(deg[y]==mx)cnt++,need_update=true; if(need_update)global_answer=get_answer(); } int CountCritical(){ return global_answer; } /* 7 13 -1 1 2 -1 0 5 -1 2 0 -1 3 2 -1 3 5 -1 4 3 -1 */

Compilation message (stderr)

rings.cpp: In function 'int get_answer()':
rings.cpp:89:1: warning: control reaches end of non-void function [-Wreturn-type]
   89 | }
      | ^
#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...