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>
using namespace std;
vector<int>g[1000005];
bool on[1000005],vis[1000005];
int n,deg[1000005],linker;
bool dfs(int v,int p){
bool flag=false;
vis[v]=true;
for(int to:g[v])if(to!=p){
if(on[to])continue;
if(flag)return false;
if(vis[to])return false;
if(!dfs(to,v))return false;
flag=true;
}
return true;
}
void dfs2(int v){
linker++;
vis[v]=1;
for(int to:g[v])if(!vis[to])dfs2(to);
}
bool check(){
for(int i=0;i<n;i++)vis[i]=0;
for(int i=0;i<n;i++)if(!on[i]&&!vis[i]&°[i]<2)if(!dfs(i,i))return false;
for(int i=0;i<n;i++)if(!vis[i]&&!on[i])return false;
return true;
}
void Init(int N){n=N;}
void Link(int x,int y){
g[x].push_back(y);
g[y].push_back(x);
deg[x]++;
deg[y]++;
}
int CountCritical(){
int mx=-1,cnt=0;
for(int i=0;i<n;i++)
if(deg[i]>mx){
mx=deg[i];
cnt=1;
}else if(deg[i]==mx)cnt++;
if(mx>=4){
if(cnt!=1)return 0;
cnt=0;
for(int i=0;i<n;i++){
if(deg[i]==mx){
on[i]=true;
for(auto to:g[i])deg[to]--;
cnt+=check();
for(auto to:g[i])deg[to]++;
on[i]=false;
}
}
return cnt;
}else if(mx<2)return n;
else if(mx==2){
for(int i=0;i<n;i++)vis[i]=0;
for(int i=0;i<n;i++)if(!vis[i]&°[i]<2)dfs(i,i);
bool flag=false;
for(int i=0;i<n;i++)if(!vis[i]){
if(flag)return 0;
linker=0;
dfs2(i);
flag=true;
}
if(flag)return linker;
return n;
}else if(mx==3){
for(int i=0;i<n;i++){
cnt=0;
if(mx==deg[i]){
on[i]=true;
for(auto to:g[i])deg[to]--;
cnt+=check();
for(auto to:g[i])deg[to]++;
on[i]=false;
for(int to:g[i]){
on[to]=true;
for(auto to2:g[to])deg[to2]--;
cnt+=check();
for(auto to2:g[to])deg[to2]++;
on[to]=false;
}
return cnt;
}
}
}
}
Compilation message (stderr)
rings.cpp: In function 'int CountCritical()':
rings.cpp:89:1: warning: control reaches end of non-void function [-Wreturn-type]
89 | }
| ^
# | 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... |