#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int N;
int who,x,y;
vector < int > Next[1000005];
int deg[1000005];
int big[1000005];
int con[1000005];
int tt=0;
bool have[1000005];
int ok=1;
void Init(int N_)
{
N = N_;
}
void Link(int A, int B)
{
Next[A].push_back(B);
Next[B].push_back(A);
if(deg[A]==2)
{
tt++;
for(auto i:Next[A]) con[i]++;
}
if(deg[A]==3)
{
for(auto i:Next[A]) if(i!=B) con[i]--;
}
if(deg[B]==2)
{
tt++;
for(auto i:Next[B]) con[i]++;
}
if(deg[B]==3)
{
for(auto i:Next[B]) if(i!=A) con[i]--;
}
deg[A]++;
deg[B]++;
}
void F(int here)
{
y++;
int t=0;
have[here]=1;
for(auto i:Next[here]) if(!have[i]&&i!=who) F(i);
}
int CountCritical()
{
int ans=0;
int i,j;
for(i=0;i<N;i++)
{
if(deg[i]>=3)
{
break;
}
}
if(i==N)
{
x=y=0;
ok=1;
who=-1;
for(j=0;j<N;j++) have[j]=0;
for(j=0;j<N;j++)
{
if(deg[j]==0) have[j]=1;
if(deg[j]==1&&!have[j]) F(j);
}
for(j=0;j<N;j++)
{
if(!have[j])
{
who=-1;
x++;
y=0;
F(j);
}
ans+=x;
}
if(x==0) return N;
if(x==1) return y;
return 0;
}
for(i=0;i<N;i++)
{
ok=1;
who=i;
//printf("%d %d %d\n",i,con[i],tt);
if(deg[i]>=3)
{
if(tt-con[i]>1) continue;
}
else if(tt-con[i]) continue;
//printf("aa %d\n",i);
for(auto j:Next[i]) deg[j]--;
if(ok)
{
for(j=0;j<N;j++) have[j]=0;
have[i]=1;
for(j=0;j<N;j++)
{
if(deg[j]==0) have[j]=1;
if(deg[j]==1&&!have[j]) F(j);
if(deg[j]>=3&&i!=j) ok=0;
}
for(j=0;j<N;j++) if(!have[j]) ok=0;
}
for(auto j:Next[i]) deg[j]++;
ans+=ok;
}
return ans;
}
Compilation message
rings.cpp: In function 'void F(int)':
rings.cpp:49:9: warning: unused variable 't' [-Wunused-variable]
49 | int t=0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
24044 KB |
Output is correct |
3 |
Correct |
18 ms |
24044 KB |
Output is correct |
4 |
Correct |
18 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
18 ms |
24172 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
24044 KB |
Output is correct |
9 |
Correct |
19 ms |
24044 KB |
Output is correct |
10 |
Correct |
18 ms |
24172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
559 ms |
42980 KB |
Output is correct |
2 |
Correct |
976 ms |
52972 KB |
Output is correct |
3 |
Correct |
978 ms |
59032 KB |
Output is correct |
4 |
Correct |
1236 ms |
60472 KB |
Output is correct |
5 |
Correct |
1232 ms |
60624 KB |
Output is correct |
6 |
Correct |
1216 ms |
74256 KB |
Output is correct |
7 |
Correct |
903 ms |
58732 KB |
Output is correct |
8 |
Correct |
1393 ms |
57984 KB |
Output is correct |
9 |
Correct |
1238 ms |
60396 KB |
Output is correct |
10 |
Correct |
958 ms |
60780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
24044 KB |
Output is correct |
3 |
Correct |
18 ms |
24044 KB |
Output is correct |
4 |
Correct |
18 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
18 ms |
24172 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
24044 KB |
Output is correct |
9 |
Correct |
19 ms |
24044 KB |
Output is correct |
10 |
Correct |
18 ms |
24172 KB |
Output is correct |
11 |
Correct |
29 ms |
24044 KB |
Output is correct |
12 |
Correct |
41 ms |
24300 KB |
Output is correct |
13 |
Correct |
54 ms |
24300 KB |
Output is correct |
14 |
Correct |
33 ms |
24172 KB |
Output is correct |
15 |
Correct |
36 ms |
24300 KB |
Output is correct |
16 |
Correct |
36 ms |
24300 KB |
Output is correct |
17 |
Correct |
22 ms |
24300 KB |
Output is correct |
18 |
Correct |
24 ms |
24556 KB |
Output is correct |
19 |
Correct |
43 ms |
24300 KB |
Output is correct |
20 |
Correct |
47 ms |
24428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
24044 KB |
Output is correct |
3 |
Correct |
18 ms |
24044 KB |
Output is correct |
4 |
Correct |
18 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
18 ms |
24172 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
24044 KB |
Output is correct |
9 |
Correct |
19 ms |
24044 KB |
Output is correct |
10 |
Correct |
18 ms |
24172 KB |
Output is correct |
11 |
Correct |
29 ms |
24044 KB |
Output is correct |
12 |
Correct |
41 ms |
24300 KB |
Output is correct |
13 |
Correct |
54 ms |
24300 KB |
Output is correct |
14 |
Correct |
33 ms |
24172 KB |
Output is correct |
15 |
Correct |
36 ms |
24300 KB |
Output is correct |
16 |
Correct |
36 ms |
24300 KB |
Output is correct |
17 |
Correct |
22 ms |
24300 KB |
Output is correct |
18 |
Correct |
24 ms |
24556 KB |
Output is correct |
19 |
Correct |
43 ms |
24300 KB |
Output is correct |
20 |
Correct |
47 ms |
24428 KB |
Output is correct |
21 |
Execution timed out |
4078 ms |
25116 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
24044 KB |
Output is correct |
3 |
Correct |
18 ms |
24044 KB |
Output is correct |
4 |
Correct |
18 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
18 ms |
24172 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
24044 KB |
Output is correct |
9 |
Correct |
19 ms |
24044 KB |
Output is correct |
10 |
Correct |
18 ms |
24172 KB |
Output is correct |
11 |
Correct |
559 ms |
42980 KB |
Output is correct |
12 |
Correct |
976 ms |
52972 KB |
Output is correct |
13 |
Correct |
978 ms |
59032 KB |
Output is correct |
14 |
Correct |
1236 ms |
60472 KB |
Output is correct |
15 |
Correct |
1232 ms |
60624 KB |
Output is correct |
16 |
Correct |
1216 ms |
74256 KB |
Output is correct |
17 |
Correct |
903 ms |
58732 KB |
Output is correct |
18 |
Correct |
1393 ms |
57984 KB |
Output is correct |
19 |
Correct |
1238 ms |
60396 KB |
Output is correct |
20 |
Correct |
958 ms |
60780 KB |
Output is correct |
21 |
Correct |
29 ms |
24044 KB |
Output is correct |
22 |
Correct |
41 ms |
24300 KB |
Output is correct |
23 |
Correct |
54 ms |
24300 KB |
Output is correct |
24 |
Correct |
33 ms |
24172 KB |
Output is correct |
25 |
Correct |
36 ms |
24300 KB |
Output is correct |
26 |
Correct |
36 ms |
24300 KB |
Output is correct |
27 |
Correct |
22 ms |
24300 KB |
Output is correct |
28 |
Correct |
24 ms |
24556 KB |
Output is correct |
29 |
Correct |
43 ms |
24300 KB |
Output is correct |
30 |
Correct |
47 ms |
24428 KB |
Output is correct |
31 |
Execution timed out |
4078 ms |
25116 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |