#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <set>
using namespace std;
int N;
int who;
vector < int > Next[1000005],tt;
int deg[1000005];
bool have[1000005];
int ok=1;
int x=0,y=0;
set < int > xxx;
void Init(int N_)
{
N = N_;
}
void Link(int A, int B)
{
Next[A].push_back(B);
Next[B].push_back(A);
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,now=0;
int i,j;
tt.clear();
xxx.clear();
for(i=0;i<N;i++)
{
if(deg[i]>=3)
{
tt.push_back(i);
now++;
}
}
if(now==0)
{
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;
}
else if(now==1)
{
//printf("bb %d\n",ans);
for(auto i:tt)
{
ok=1;
who=i;
for(auto j:Next[i]) deg[j]--;
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;
}
if(deg[tt[0]]==3)
{
for(auto i:Next[tt[0]])
{
ok=1;
who=i;
for(auto j:Next[i]) deg[j]--;
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;
}
else if(now==2)
{
for(auto i:tt)
{
ok=1;
who=i;
for(auto j:Next[i]) deg[j]--;
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]++;
if(ok) xxx.insert(i);
}
if(deg[tt[0]]==3)
{
for(auto i:Next[tt[0]])
{
ok=1;
who=i;
for(auto j:Next[i]) deg[j]--;
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]++;
if(ok) xxx.insert(i);
}
}
if(deg[tt[1]]==3)
{
for(auto i:Next[tt[1]])
{
ok=1;
who=i;
for(auto j:Next[i]) deg[j]--;
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]++;
if(ok) xxx.insert(i);
}
}
return xxx.size();
}
else return 0;
}
Compilation message
rings.cpp: In function 'void F(int)':
rings.cpp:29:9: warning: unused variable 't' [-Wunused-variable]
29 | int t=0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
24064 KB |
Output is correct |
2 |
Correct |
24 ms |
24044 KB |
Output is correct |
3 |
Correct |
21 ms |
24044 KB |
Output is correct |
4 |
Correct |
21 ms |
23788 KB |
Output is correct |
5 |
Correct |
23 ms |
24044 KB |
Output is correct |
6 |
Correct |
20 ms |
24172 KB |
Output is correct |
7 |
Correct |
20 ms |
23916 KB |
Output is correct |
8 |
Correct |
26 ms |
24044 KB |
Output is correct |
9 |
Correct |
20 ms |
24044 KB |
Output is correct |
10 |
Correct |
21 ms |
24044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
661 ms |
45312 KB |
Output is correct |
2 |
Correct |
1145 ms |
53540 KB |
Output is correct |
3 |
Correct |
1026 ms |
57828 KB |
Output is correct |
4 |
Correct |
1522 ms |
60944 KB |
Output is correct |
5 |
Correct |
1343 ms |
61224 KB |
Output is correct |
6 |
Correct |
1481 ms |
74900 KB |
Output is correct |
7 |
Correct |
1094 ms |
57308 KB |
Output is correct |
8 |
Correct |
3047 ms |
58596 KB |
Output is correct |
9 |
Correct |
3424 ms |
61120 KB |
Output is correct |
10 |
Correct |
1030 ms |
66440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
24064 KB |
Output is correct |
2 |
Correct |
24 ms |
24044 KB |
Output is correct |
3 |
Correct |
21 ms |
24044 KB |
Output is correct |
4 |
Correct |
21 ms |
23788 KB |
Output is correct |
5 |
Correct |
23 ms |
24044 KB |
Output is correct |
6 |
Correct |
20 ms |
24172 KB |
Output is correct |
7 |
Correct |
20 ms |
23916 KB |
Output is correct |
8 |
Correct |
26 ms |
24044 KB |
Output is correct |
9 |
Correct |
20 ms |
24044 KB |
Output is correct |
10 |
Correct |
21 ms |
24044 KB |
Output is correct |
11 |
Incorrect |
29 ms |
24320 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
24064 KB |
Output is correct |
2 |
Correct |
24 ms |
24044 KB |
Output is correct |
3 |
Correct |
21 ms |
24044 KB |
Output is correct |
4 |
Correct |
21 ms |
23788 KB |
Output is correct |
5 |
Correct |
23 ms |
24044 KB |
Output is correct |
6 |
Correct |
20 ms |
24172 KB |
Output is correct |
7 |
Correct |
20 ms |
23916 KB |
Output is correct |
8 |
Correct |
26 ms |
24044 KB |
Output is correct |
9 |
Correct |
20 ms |
24044 KB |
Output is correct |
10 |
Correct |
21 ms |
24044 KB |
Output is correct |
11 |
Incorrect |
29 ms |
24320 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
24064 KB |
Output is correct |
2 |
Correct |
24 ms |
24044 KB |
Output is correct |
3 |
Correct |
21 ms |
24044 KB |
Output is correct |
4 |
Correct |
21 ms |
23788 KB |
Output is correct |
5 |
Correct |
23 ms |
24044 KB |
Output is correct |
6 |
Correct |
20 ms |
24172 KB |
Output is correct |
7 |
Correct |
20 ms |
23916 KB |
Output is correct |
8 |
Correct |
26 ms |
24044 KB |
Output is correct |
9 |
Correct |
20 ms |
24044 KB |
Output is correct |
10 |
Correct |
21 ms |
24044 KB |
Output is correct |
11 |
Correct |
661 ms |
45312 KB |
Output is correct |
12 |
Correct |
1145 ms |
53540 KB |
Output is correct |
13 |
Correct |
1026 ms |
57828 KB |
Output is correct |
14 |
Correct |
1522 ms |
60944 KB |
Output is correct |
15 |
Correct |
1343 ms |
61224 KB |
Output is correct |
16 |
Correct |
1481 ms |
74900 KB |
Output is correct |
17 |
Correct |
1094 ms |
57308 KB |
Output is correct |
18 |
Correct |
3047 ms |
58596 KB |
Output is correct |
19 |
Correct |
3424 ms |
61120 KB |
Output is correct |
20 |
Correct |
1030 ms |
66440 KB |
Output is correct |
21 |
Incorrect |
29 ms |
24320 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |