#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[6];
bool flag;
#define DEBUG(x) cout<<#x<<"="<<x<<"\n"
int cycle_number,cycle_size;
void update_counter(int x,int y){
counter[min(x,5)]+=y;
}
void go(int v,int p){
if(on[v])return;
cycle_size++;
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;
}
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);
}
int CountCritical(){
if(counter[4]+counter[5]>0){
if(counter[4]+counter[5]!=1)return 0;
for(int i=0;i<n;i++){
if(deg[i]>3){
on[i]=true;
for(auto to:g[i])deg[to]--;
int cnt=check();
for(auto to:g[i])deg[to]++;
on[i]=false;
return cnt;
}
}
}else if(counter[3]){
for(int i=0;i<n;i++){
int cnt=0;
if(deg[i]==3){
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;
}
}
}else if(counter[2]){
for(int i=0;i<n;i++)vis[i]=0;
cycle_number=0,cycle_size=0;
for(int i=0;i<n;i++)
if(!vis[i]){
flag=false;
go(i,i);
if(flag)cycle_number++;
else if(!cycle_number)cycle_size=0;
}
if(cycle_number==0)return n;
else if(cycle_number==1)return cycle_size;
else return 0;
}else return n;
}
/*
7 13
-1
1 2
-1
0 5
-1
2 0
-1
3 2
-1
3 5
-1
4 3
-1
*/
Compilation message
rings.cpp: In function 'int CountCritical()':
rings.cpp:100:1: warning: control reaches end of non-void function [-Wreturn-type]
100 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23832 KB |
Output is correct |
2 |
Correct |
17 ms |
24044 KB |
Output is correct |
3 |
Correct |
18 ms |
24020 KB |
Output is correct |
4 |
Incorrect |
16 ms |
23932 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
550 ms |
42716 KB |
Output is correct |
2 |
Correct |
1020 ms |
52956 KB |
Output is correct |
3 |
Correct |
937 ms |
55020 KB |
Output is correct |
4 |
Incorrect |
1278 ms |
60396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23832 KB |
Output is correct |
2 |
Correct |
17 ms |
24044 KB |
Output is correct |
3 |
Correct |
18 ms |
24020 KB |
Output is correct |
4 |
Incorrect |
16 ms |
23932 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23832 KB |
Output is correct |
2 |
Correct |
17 ms |
24044 KB |
Output is correct |
3 |
Correct |
18 ms |
24020 KB |
Output is correct |
4 |
Incorrect |
16 ms |
23932 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23832 KB |
Output is correct |
2 |
Correct |
17 ms |
24044 KB |
Output is correct |
3 |
Correct |
18 ms |
24020 KB |
Output is correct |
4 |
Incorrect |
16 ms |
23932 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |