#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],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;
}
}
}
}
/*
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:92:1: warning: control reaches end of non-void function [-Wreturn-type]
92 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
18 ms |
24172 KB |
Output is correct |
3 |
Correct |
18 ms |
24044 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
18 ms |
24044 KB |
Output is correct |
6 |
Correct |
19 ms |
24172 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
20 ms |
24172 KB |
Output is correct |
9 |
Correct |
19 ms |
24172 KB |
Output is correct |
10 |
Correct |
19 ms |
24172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
571 ms |
42792 KB |
Output is correct |
2 |
Correct |
999 ms |
53228 KB |
Output is correct |
3 |
Correct |
950 ms |
55160 KB |
Output is correct |
4 |
Correct |
1297 ms |
60512 KB |
Output is correct |
5 |
Correct |
1285 ms |
74160 KB |
Output is correct |
6 |
Correct |
1280 ms |
87384 KB |
Output is correct |
7 |
Correct |
887 ms |
67692 KB |
Output is correct |
8 |
Correct |
1652 ms |
70764 KB |
Output is correct |
9 |
Correct |
1294 ms |
74708 KB |
Output is correct |
10 |
Correct |
714 ms |
72744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
18 ms |
24172 KB |
Output is correct |
3 |
Correct |
18 ms |
24044 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
18 ms |
24044 KB |
Output is correct |
6 |
Correct |
19 ms |
24172 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
20 ms |
24172 KB |
Output is correct |
9 |
Correct |
19 ms |
24172 KB |
Output is correct |
10 |
Correct |
19 ms |
24172 KB |
Output is correct |
11 |
Correct |
34 ms |
24172 KB |
Output is correct |
12 |
Correct |
47 ms |
24428 KB |
Output is correct |
13 |
Correct |
65 ms |
24380 KB |
Output is correct |
14 |
Correct |
38 ms |
24300 KB |
Output is correct |
15 |
Correct |
58 ms |
24172 KB |
Output is correct |
16 |
Correct |
41 ms |
24300 KB |
Output is correct |
17 |
Correct |
30 ms |
24300 KB |
Output is correct |
18 |
Correct |
32 ms |
24428 KB |
Output is correct |
19 |
Correct |
47 ms |
24340 KB |
Output is correct |
20 |
Correct |
67 ms |
24428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
18 ms |
24172 KB |
Output is correct |
3 |
Correct |
18 ms |
24044 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
18 ms |
24044 KB |
Output is correct |
6 |
Correct |
19 ms |
24172 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
20 ms |
24172 KB |
Output is correct |
9 |
Correct |
19 ms |
24172 KB |
Output is correct |
10 |
Correct |
19 ms |
24172 KB |
Output is correct |
11 |
Correct |
34 ms |
24172 KB |
Output is correct |
12 |
Correct |
47 ms |
24428 KB |
Output is correct |
13 |
Correct |
65 ms |
24380 KB |
Output is correct |
14 |
Correct |
38 ms |
24300 KB |
Output is correct |
15 |
Correct |
58 ms |
24172 KB |
Output is correct |
16 |
Correct |
41 ms |
24300 KB |
Output is correct |
17 |
Correct |
30 ms |
24300 KB |
Output is correct |
18 |
Correct |
32 ms |
24428 KB |
Output is correct |
19 |
Correct |
47 ms |
24340 KB |
Output is correct |
20 |
Correct |
67 ms |
24428 KB |
Output is correct |
21 |
Execution timed out |
4049 ms |
24708 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
18 ms |
24172 KB |
Output is correct |
3 |
Correct |
18 ms |
24044 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
18 ms |
24044 KB |
Output is correct |
6 |
Correct |
19 ms |
24172 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
20 ms |
24172 KB |
Output is correct |
9 |
Correct |
19 ms |
24172 KB |
Output is correct |
10 |
Correct |
19 ms |
24172 KB |
Output is correct |
11 |
Correct |
571 ms |
42792 KB |
Output is correct |
12 |
Correct |
999 ms |
53228 KB |
Output is correct |
13 |
Correct |
950 ms |
55160 KB |
Output is correct |
14 |
Correct |
1297 ms |
60512 KB |
Output is correct |
15 |
Correct |
1285 ms |
74160 KB |
Output is correct |
16 |
Correct |
1280 ms |
87384 KB |
Output is correct |
17 |
Correct |
887 ms |
67692 KB |
Output is correct |
18 |
Correct |
1652 ms |
70764 KB |
Output is correct |
19 |
Correct |
1294 ms |
74708 KB |
Output is correct |
20 |
Correct |
714 ms |
72744 KB |
Output is correct |
21 |
Correct |
34 ms |
24172 KB |
Output is correct |
22 |
Correct |
47 ms |
24428 KB |
Output is correct |
23 |
Correct |
65 ms |
24380 KB |
Output is correct |
24 |
Correct |
38 ms |
24300 KB |
Output is correct |
25 |
Correct |
58 ms |
24172 KB |
Output is correct |
26 |
Correct |
41 ms |
24300 KB |
Output is correct |
27 |
Correct |
30 ms |
24300 KB |
Output is correct |
28 |
Correct |
32 ms |
24428 KB |
Output is correct |
29 |
Correct |
47 ms |
24340 KB |
Output is correct |
30 |
Correct |
67 ms |
24428 KB |
Output is correct |
31 |
Execution timed out |
4049 ms |
24708 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |