#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>=3){
if(cnt!=1&&mx!=3)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;
if(mx==3)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(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;
}
}
Compilation message
rings.cpp: In function 'int CountCritical()':
rings.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]
77 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
Output is correct |
2 |
Correct |
20 ms |
24044 KB |
Output is correct |
3 |
Correct |
21 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 |
18 ms |
24172 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
24044 KB |
Output is correct |
9 |
Correct |
19 ms |
24172 KB |
Output is correct |
10 |
Correct |
21 ms |
24044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
543 ms |
42860 KB |
Output is correct |
2 |
Correct |
990 ms |
53100 KB |
Output is correct |
3 |
Correct |
939 ms |
55020 KB |
Output is correct |
4 |
Correct |
1251 ms |
60812 KB |
Output is correct |
5 |
Correct |
1261 ms |
60672 KB |
Output is correct |
6 |
Correct |
1241 ms |
74188 KB |
Output is correct |
7 |
Correct |
900 ms |
55532 KB |
Output is correct |
8 |
Correct |
1646 ms |
58588 KB |
Output is correct |
9 |
Correct |
1269 ms |
60908 KB |
Output is correct |
10 |
Correct |
696 ms |
60140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
Output is correct |
2 |
Correct |
20 ms |
24044 KB |
Output is correct |
3 |
Correct |
21 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 |
18 ms |
24172 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
24044 KB |
Output is correct |
9 |
Correct |
19 ms |
24172 KB |
Output is correct |
10 |
Correct |
21 ms |
24044 KB |
Output is correct |
11 |
Correct |
31 ms |
24044 KB |
Output is correct |
12 |
Correct |
45 ms |
24300 KB |
Output is correct |
13 |
Correct |
60 ms |
24300 KB |
Output is correct |
14 |
Correct |
34 ms |
24044 KB |
Output is correct |
15 |
Correct |
44 ms |
24044 KB |
Output is correct |
16 |
Correct |
40 ms |
24304 KB |
Output is correct |
17 |
Correct |
27 ms |
24300 KB |
Output is correct |
18 |
Correct |
26 ms |
24428 KB |
Output is correct |
19 |
Correct |
46 ms |
24300 KB |
Output is correct |
20 |
Correct |
58 ms |
24300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
Output is correct |
2 |
Correct |
20 ms |
24044 KB |
Output is correct |
3 |
Correct |
21 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 |
18 ms |
24172 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
24044 KB |
Output is correct |
9 |
Correct |
19 ms |
24172 KB |
Output is correct |
10 |
Correct |
21 ms |
24044 KB |
Output is correct |
11 |
Correct |
31 ms |
24044 KB |
Output is correct |
12 |
Correct |
45 ms |
24300 KB |
Output is correct |
13 |
Correct |
60 ms |
24300 KB |
Output is correct |
14 |
Correct |
34 ms |
24044 KB |
Output is correct |
15 |
Correct |
44 ms |
24044 KB |
Output is correct |
16 |
Correct |
40 ms |
24304 KB |
Output is correct |
17 |
Correct |
27 ms |
24300 KB |
Output is correct |
18 |
Correct |
26 ms |
24428 KB |
Output is correct |
19 |
Correct |
46 ms |
24300 KB |
Output is correct |
20 |
Correct |
58 ms |
24300 KB |
Output is correct |
21 |
Execution timed out |
4099 ms |
24472 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
Output is correct |
2 |
Correct |
20 ms |
24044 KB |
Output is correct |
3 |
Correct |
21 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 |
18 ms |
24172 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
24044 KB |
Output is correct |
9 |
Correct |
19 ms |
24172 KB |
Output is correct |
10 |
Correct |
21 ms |
24044 KB |
Output is correct |
11 |
Correct |
543 ms |
42860 KB |
Output is correct |
12 |
Correct |
990 ms |
53100 KB |
Output is correct |
13 |
Correct |
939 ms |
55020 KB |
Output is correct |
14 |
Correct |
1251 ms |
60812 KB |
Output is correct |
15 |
Correct |
1261 ms |
60672 KB |
Output is correct |
16 |
Correct |
1241 ms |
74188 KB |
Output is correct |
17 |
Correct |
900 ms |
55532 KB |
Output is correct |
18 |
Correct |
1646 ms |
58588 KB |
Output is correct |
19 |
Correct |
1269 ms |
60908 KB |
Output is correct |
20 |
Correct |
696 ms |
60140 KB |
Output is correct |
21 |
Correct |
31 ms |
24044 KB |
Output is correct |
22 |
Correct |
45 ms |
24300 KB |
Output is correct |
23 |
Correct |
60 ms |
24300 KB |
Output is correct |
24 |
Correct |
34 ms |
24044 KB |
Output is correct |
25 |
Correct |
44 ms |
24044 KB |
Output is correct |
26 |
Correct |
40 ms |
24304 KB |
Output is correct |
27 |
Correct |
27 ms |
24300 KB |
Output is correct |
28 |
Correct |
26 ms |
24428 KB |
Output is correct |
29 |
Correct |
46 ms |
24300 KB |
Output is correct |
30 |
Correct |
58 ms |
24300 KB |
Output is correct |
31 |
Execution timed out |
4099 ms |
24472 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |