int N;
const int MN = 1000010;
struct str{
int p[MN],r[MN];
int deg[MN];
int px;
bool ch;
void init(int x){
int i;
for(i=0;i<N;i++){deg[i]=0,p[i]=i,r[i]=1;}
px=x,ch=true;
}
int Find(int x){
while(x!=p[x])x=p[x];
return x;
}
bool Union(int x,int y){
deg[x]++,deg[y]++;
int a=Find(x),b=Find(y);
if(a==b)return true;
if(r[a]>r[b]){p[b]=a,r[a]+=r[b],r[b]=0;}
else{p[a]=b,r[b]+=r[a],r[a]=0;}
return false;
}
}ring[5];
int ans;
int cnt;
bool flag_3;
bool flag_cycle;
int st[MN],en[MN<<1],next[MN<<1];
int in[MN][2];
void addedge(int s,int d,int c)
{
next[c]=st[s];
st[s]=c;
en[c]=d;
}
void Init(int N_){
ans = N = N_;
ring[0].init(0);
}
void make_ring(int arr[])
{
int i,j;
for(i=0;i<4;i++){
ring[i].init(arr[i]);
for(j=1;j<=cnt;j++){
if(in[j][0]==arr[i]||in[j][1]==arr[i])continue;
if(ring[i].Union(in[j][0],in[j][1]))ring[i].ch=false;
if(ring[i].deg[in[j][0]]>=3 || ring[i].deg[in[j][1]]>=3)ring[i].ch=false;
}
}
}
void Link(int A, int B){
cnt++;
addedge(A,B,2*cnt);
addedge(B,A,2*cnt+1);
in[cnt][0]=A,in[cnt][1]=B;
if(flag_3){
int i;
for(i=0;i<4;i++){
if(A!=ring[i].px && B!=ring[i].px){
if(ring[i].Union(A,B))ring[i].ch=false;
if(ring[i].deg[A]>=3 || ring[i].deg[B]>=3)ring[i].ch=false;
}
}
return;
}
if(ring[0].Union(A,B)){
if(flag_cycle)ans=0;
else{
int ta=ring[0].Find(A);
ans=ring[0].r[ta];
flag_cycle=1;
}
}
if(ring[0].deg[A]>=3){
int arr[5]={A};
int i,tmp=1;
for(i=st[A];i;i=next[i]){
arr[tmp++]=en[i];
}
make_ring(arr);
flag_3 = true;
}
else if(ring[0].deg[B]>=3){
int arr[5]={B};
int i,tmp=1;
for(i=st[B];i;i=next[i]){
arr[tmp++]=en[i];
}
make_ring(arr);
flag_3 = true;
}
}
int CountCritical(){
if(flag_3){
int i,ret=0;
for(i=0;i<4;i++){
if(ring[i].ch)ret++;
}
return ret;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
756 KB |
Output is correct |
3 |
Correct |
4 ms |
920 KB |
Output is correct |
4 |
Correct |
2 ms |
920 KB |
Output is correct |
5 |
Correct |
3 ms |
920 KB |
Output is correct |
6 |
Correct |
3 ms |
920 KB |
Output is correct |
7 |
Correct |
2 ms |
920 KB |
Output is correct |
8 |
Correct |
3 ms |
920 KB |
Output is correct |
9 |
Correct |
4 ms |
972 KB |
Output is correct |
10 |
Correct |
6 ms |
1096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
266 ms |
20832 KB |
Output is correct |
2 |
Correct |
1122 ms |
60196 KB |
Output is correct |
3 |
Correct |
1503 ms |
73792 KB |
Output is correct |
4 |
Correct |
610 ms |
73792 KB |
Output is correct |
5 |
Correct |
601 ms |
73792 KB |
Output is correct |
6 |
Correct |
570 ms |
73792 KB |
Output is correct |
7 |
Correct |
1337 ms |
73792 KB |
Output is correct |
8 |
Correct |
1123 ms |
73792 KB |
Output is correct |
9 |
Correct |
1095 ms |
75104 KB |
Output is correct |
10 |
Correct |
495 ms |
75104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
756 KB |
Output is correct |
3 |
Correct |
4 ms |
920 KB |
Output is correct |
4 |
Correct |
2 ms |
920 KB |
Output is correct |
5 |
Correct |
3 ms |
920 KB |
Output is correct |
6 |
Correct |
3 ms |
920 KB |
Output is correct |
7 |
Correct |
2 ms |
920 KB |
Output is correct |
8 |
Correct |
3 ms |
920 KB |
Output is correct |
9 |
Correct |
4 ms |
972 KB |
Output is correct |
10 |
Correct |
6 ms |
1096 KB |
Output is correct |
11 |
Correct |
4 ms |
75104 KB |
Output is correct |
12 |
Correct |
7 ms |
75104 KB |
Output is correct |
13 |
Correct |
7 ms |
75104 KB |
Output is correct |
14 |
Correct |
5 ms |
75104 KB |
Output is correct |
15 |
Correct |
5 ms |
75104 KB |
Output is correct |
16 |
Correct |
5 ms |
75104 KB |
Output is correct |
17 |
Correct |
6 ms |
75104 KB |
Output is correct |
18 |
Correct |
8 ms |
75104 KB |
Output is correct |
19 |
Correct |
5 ms |
75104 KB |
Output is correct |
20 |
Correct |
6 ms |
75104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
756 KB |
Output is correct |
3 |
Correct |
4 ms |
920 KB |
Output is correct |
4 |
Correct |
2 ms |
920 KB |
Output is correct |
5 |
Correct |
3 ms |
920 KB |
Output is correct |
6 |
Correct |
3 ms |
920 KB |
Output is correct |
7 |
Correct |
2 ms |
920 KB |
Output is correct |
8 |
Correct |
3 ms |
920 KB |
Output is correct |
9 |
Correct |
4 ms |
972 KB |
Output is correct |
10 |
Correct |
6 ms |
1096 KB |
Output is correct |
11 |
Correct |
4 ms |
75104 KB |
Output is correct |
12 |
Correct |
7 ms |
75104 KB |
Output is correct |
13 |
Correct |
7 ms |
75104 KB |
Output is correct |
14 |
Correct |
5 ms |
75104 KB |
Output is correct |
15 |
Correct |
5 ms |
75104 KB |
Output is correct |
16 |
Correct |
5 ms |
75104 KB |
Output is correct |
17 |
Correct |
6 ms |
75104 KB |
Output is correct |
18 |
Correct |
8 ms |
75104 KB |
Output is correct |
19 |
Correct |
5 ms |
75104 KB |
Output is correct |
20 |
Correct |
6 ms |
75104 KB |
Output is correct |
21 |
Correct |
18 ms |
75104 KB |
Output is correct |
22 |
Correct |
28 ms |
75104 KB |
Output is correct |
23 |
Correct |
34 ms |
75104 KB |
Output is correct |
24 |
Correct |
44 ms |
75104 KB |
Output is correct |
25 |
Correct |
20 ms |
75104 KB |
Output is correct |
26 |
Correct |
43 ms |
75104 KB |
Output is correct |
27 |
Correct |
37 ms |
75104 KB |
Output is correct |
28 |
Correct |
45 ms |
75104 KB |
Output is correct |
29 |
Correct |
37 ms |
75104 KB |
Output is correct |
30 |
Correct |
38 ms |
75104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
756 KB |
Output is correct |
3 |
Correct |
4 ms |
920 KB |
Output is correct |
4 |
Correct |
2 ms |
920 KB |
Output is correct |
5 |
Correct |
3 ms |
920 KB |
Output is correct |
6 |
Correct |
3 ms |
920 KB |
Output is correct |
7 |
Correct |
2 ms |
920 KB |
Output is correct |
8 |
Correct |
3 ms |
920 KB |
Output is correct |
9 |
Correct |
4 ms |
972 KB |
Output is correct |
10 |
Correct |
6 ms |
1096 KB |
Output is correct |
11 |
Correct |
266 ms |
20832 KB |
Output is correct |
12 |
Correct |
1122 ms |
60196 KB |
Output is correct |
13 |
Correct |
1503 ms |
73792 KB |
Output is correct |
14 |
Correct |
610 ms |
73792 KB |
Output is correct |
15 |
Correct |
601 ms |
73792 KB |
Output is correct |
16 |
Correct |
570 ms |
73792 KB |
Output is correct |
17 |
Correct |
1337 ms |
73792 KB |
Output is correct |
18 |
Correct |
1123 ms |
73792 KB |
Output is correct |
19 |
Correct |
1095 ms |
75104 KB |
Output is correct |
20 |
Correct |
495 ms |
75104 KB |
Output is correct |
21 |
Correct |
4 ms |
75104 KB |
Output is correct |
22 |
Correct |
7 ms |
75104 KB |
Output is correct |
23 |
Correct |
7 ms |
75104 KB |
Output is correct |
24 |
Correct |
5 ms |
75104 KB |
Output is correct |
25 |
Correct |
5 ms |
75104 KB |
Output is correct |
26 |
Correct |
5 ms |
75104 KB |
Output is correct |
27 |
Correct |
6 ms |
75104 KB |
Output is correct |
28 |
Correct |
8 ms |
75104 KB |
Output is correct |
29 |
Correct |
5 ms |
75104 KB |
Output is correct |
30 |
Correct |
6 ms |
75104 KB |
Output is correct |
31 |
Correct |
18 ms |
75104 KB |
Output is correct |
32 |
Correct |
28 ms |
75104 KB |
Output is correct |
33 |
Correct |
34 ms |
75104 KB |
Output is correct |
34 |
Correct |
44 ms |
75104 KB |
Output is correct |
35 |
Correct |
20 ms |
75104 KB |
Output is correct |
36 |
Correct |
43 ms |
75104 KB |
Output is correct |
37 |
Correct |
37 ms |
75104 KB |
Output is correct |
38 |
Correct |
45 ms |
75104 KB |
Output is correct |
39 |
Correct |
37 ms |
75104 KB |
Output is correct |
40 |
Correct |
38 ms |
75104 KB |
Output is correct |
41 |
Correct |
178 ms |
75104 KB |
Output is correct |
42 |
Correct |
516 ms |
75104 KB |
Output is correct |
43 |
Correct |
317 ms |
75104 KB |
Output is correct |
44 |
Correct |
699 ms |
75104 KB |
Output is correct |
45 |
Correct |
926 ms |
75104 KB |
Output is correct |
46 |
Correct |
482 ms |
75104 KB |
Output is correct |
47 |
Correct |
516 ms |
75104 KB |
Output is correct |
48 |
Correct |
577 ms |
75104 KB |
Output is correct |
49 |
Correct |
473 ms |
75104 KB |
Output is correct |
50 |
Correct |
487 ms |
75104 KB |
Output is correct |
51 |
Correct |
369 ms |
75104 KB |
Output is correct |
52 |
Correct |
618 ms |
75104 KB |
Output is correct |
53 |
Correct |
579 ms |
75104 KB |
Output is correct |
54 |
Correct |
1104 ms |
75104 KB |
Output is correct |
55 |
Correct |
1428 ms |
75104 KB |
Output is correct |