#include<cstdio>
#include<algorithm>
int p,q,a,cyc,t,co[5],link[1000003][2],par[5][1000002],deg[5][1000002],cycsz,sz[1000002],rank[5][1000002];
bool overtwo,check[5];
int find(int num,int AA){if(AA==par[num][AA])return AA;else return par[num][AA]=find(num,par[num][AA]);}
void unite(int num,int AA,int BB)
{
AA=find(num,AA);BB=find(num,BB);
if(rank[num][AA]<rank[num][BB])par[num][AA]=BB;
else
{
if(rank[num][AA]==rank[num][BB])rank[num][AA]++;
par[num][BB]=AA;
}
}
void add(int r,int s)
{
for(int i=1;i<=4;i++)
{
if(check[i]==0)continue;
if(co[i]==r||co[i]==s)continue;
deg[i][r]++;deg[i][s]++;
if(deg[i][r]>=3||deg[i][s]>=3)check[i]=0;
int rr=find(i,r),ss=find(i,s);
if(rr==ss)check[i]=0;
else
{
unite(i,rr,ss);
}
}
}
void make(int r)
{
int u=1;
co[u++]=r;
for(int i=0;i<t;i++)
{
if(link[i][0]==r)co[u++]=link[i][1];
else if(link[i][1]==r)co[u++]=link[i][0];
}
for(int i=1;i<=4;i++)
{
check[i]=1;
for(int j=0;j<a;j++)par[i][j]=j,rank[i][j]=1;
}
for(int i=0;i<t;i++)add(link[i][0],link[i][1]);
}
void Init(int N)
{
a=N;
for(int i=0;i<N;i++)rank[0][i]=1,par[0][i]=i,sz[i]=1;
}
void Link(int A, int B)
{
p=A;q=B;
link[t][0]=p;link[t][1]=q;t++;
deg[0][p]++;deg[0][q]++;
if(deg[0][p]==3&&overtwo==0){
overtwo=1;
make(p);
}
else if(overtwo==0&°[0][q]==3)
{
overtwo=1;
make(q);
}
else if(overtwo==0)
{
p=find(0,p);q=find(0,q);
if(p==q){cyc++;cycsz=sz[p];}
else
{
unite(0,p,q);
sz[p]+=sz[q];
sz[q]=sz[p];
}
}
else
{
add(p,q);
}
}
int CountCritical()
{
if(cyc>1)return 0;
if(overtwo)
{
int ans=0;
for(int i=1;i<=4;i++)ans+=check[i];
return ans;
}
else
{
if(cyc)return cycsz;
else return a;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
884 KB |
Output is correct |
3 |
Correct |
4 ms |
932 KB |
Output is correct |
4 |
Correct |
2 ms |
932 KB |
Output is correct |
5 |
Correct |
3 ms |
932 KB |
Output is correct |
6 |
Correct |
3 ms |
932 KB |
Output is correct |
7 |
Correct |
2 ms |
1068 KB |
Output is correct |
8 |
Correct |
3 ms |
1068 KB |
Output is correct |
9 |
Correct |
4 ms |
1068 KB |
Output is correct |
10 |
Correct |
4 ms |
1068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
311 ms |
12864 KB |
Output is correct |
2 |
Correct |
1119 ms |
57056 KB |
Output is correct |
3 |
Correct |
452 ms |
70752 KB |
Output is correct |
4 |
Correct |
732 ms |
70752 KB |
Output is correct |
5 |
Correct |
724 ms |
70752 KB |
Output is correct |
6 |
Correct |
723 ms |
70752 KB |
Output is correct |
7 |
Correct |
420 ms |
70752 KB |
Output is correct |
8 |
Correct |
2057 ms |
70752 KB |
Output is correct |
9 |
Correct |
2755 ms |
71176 KB |
Output is correct |
10 |
Correct |
599 ms |
71176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
884 KB |
Output is correct |
3 |
Correct |
4 ms |
932 KB |
Output is correct |
4 |
Correct |
2 ms |
932 KB |
Output is correct |
5 |
Correct |
3 ms |
932 KB |
Output is correct |
6 |
Correct |
3 ms |
932 KB |
Output is correct |
7 |
Correct |
2 ms |
1068 KB |
Output is correct |
8 |
Correct |
3 ms |
1068 KB |
Output is correct |
9 |
Correct |
4 ms |
1068 KB |
Output is correct |
10 |
Correct |
4 ms |
1068 KB |
Output is correct |
11 |
Correct |
5 ms |
71176 KB |
Output is correct |
12 |
Correct |
8 ms |
71176 KB |
Output is correct |
13 |
Correct |
7 ms |
71176 KB |
Output is correct |
14 |
Correct |
5 ms |
71176 KB |
Output is correct |
15 |
Correct |
5 ms |
71176 KB |
Output is correct |
16 |
Correct |
5 ms |
71176 KB |
Output is correct |
17 |
Correct |
5 ms |
71176 KB |
Output is correct |
18 |
Correct |
6 ms |
71176 KB |
Output is correct |
19 |
Correct |
6 ms |
71176 KB |
Output is correct |
20 |
Correct |
7 ms |
71176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
884 KB |
Output is correct |
3 |
Correct |
4 ms |
932 KB |
Output is correct |
4 |
Correct |
2 ms |
932 KB |
Output is correct |
5 |
Correct |
3 ms |
932 KB |
Output is correct |
6 |
Correct |
3 ms |
932 KB |
Output is correct |
7 |
Correct |
2 ms |
1068 KB |
Output is correct |
8 |
Correct |
3 ms |
1068 KB |
Output is correct |
9 |
Correct |
4 ms |
1068 KB |
Output is correct |
10 |
Correct |
4 ms |
1068 KB |
Output is correct |
11 |
Correct |
5 ms |
71176 KB |
Output is correct |
12 |
Correct |
8 ms |
71176 KB |
Output is correct |
13 |
Correct |
7 ms |
71176 KB |
Output is correct |
14 |
Correct |
5 ms |
71176 KB |
Output is correct |
15 |
Correct |
5 ms |
71176 KB |
Output is correct |
16 |
Correct |
5 ms |
71176 KB |
Output is correct |
17 |
Correct |
5 ms |
71176 KB |
Output is correct |
18 |
Correct |
6 ms |
71176 KB |
Output is correct |
19 |
Correct |
6 ms |
71176 KB |
Output is correct |
20 |
Correct |
7 ms |
71176 KB |
Output is correct |
21 |
Correct |
17 ms |
71176 KB |
Output is correct |
22 |
Correct |
26 ms |
71176 KB |
Output is correct |
23 |
Correct |
34 ms |
71176 KB |
Output is correct |
24 |
Correct |
39 ms |
71176 KB |
Output is correct |
25 |
Correct |
18 ms |
71176 KB |
Output is correct |
26 |
Correct |
38 ms |
71176 KB |
Output is correct |
27 |
Correct |
35 ms |
71176 KB |
Output is correct |
28 |
Correct |
36 ms |
71176 KB |
Output is correct |
29 |
Correct |
37 ms |
71176 KB |
Output is correct |
30 |
Correct |
44 ms |
71176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
884 KB |
Output is correct |
3 |
Correct |
4 ms |
932 KB |
Output is correct |
4 |
Correct |
2 ms |
932 KB |
Output is correct |
5 |
Correct |
3 ms |
932 KB |
Output is correct |
6 |
Correct |
3 ms |
932 KB |
Output is correct |
7 |
Correct |
2 ms |
1068 KB |
Output is correct |
8 |
Correct |
3 ms |
1068 KB |
Output is correct |
9 |
Correct |
4 ms |
1068 KB |
Output is correct |
10 |
Correct |
4 ms |
1068 KB |
Output is correct |
11 |
Correct |
311 ms |
12864 KB |
Output is correct |
12 |
Correct |
1119 ms |
57056 KB |
Output is correct |
13 |
Correct |
452 ms |
70752 KB |
Output is correct |
14 |
Correct |
732 ms |
70752 KB |
Output is correct |
15 |
Correct |
724 ms |
70752 KB |
Output is correct |
16 |
Correct |
723 ms |
70752 KB |
Output is correct |
17 |
Correct |
420 ms |
70752 KB |
Output is correct |
18 |
Correct |
2057 ms |
70752 KB |
Output is correct |
19 |
Correct |
2755 ms |
71176 KB |
Output is correct |
20 |
Correct |
599 ms |
71176 KB |
Output is correct |
21 |
Correct |
5 ms |
71176 KB |
Output is correct |
22 |
Correct |
8 ms |
71176 KB |
Output is correct |
23 |
Correct |
7 ms |
71176 KB |
Output is correct |
24 |
Correct |
5 ms |
71176 KB |
Output is correct |
25 |
Correct |
5 ms |
71176 KB |
Output is correct |
26 |
Correct |
5 ms |
71176 KB |
Output is correct |
27 |
Correct |
5 ms |
71176 KB |
Output is correct |
28 |
Correct |
6 ms |
71176 KB |
Output is correct |
29 |
Correct |
6 ms |
71176 KB |
Output is correct |
30 |
Correct |
7 ms |
71176 KB |
Output is correct |
31 |
Correct |
17 ms |
71176 KB |
Output is correct |
32 |
Correct |
26 ms |
71176 KB |
Output is correct |
33 |
Correct |
34 ms |
71176 KB |
Output is correct |
34 |
Correct |
39 ms |
71176 KB |
Output is correct |
35 |
Correct |
18 ms |
71176 KB |
Output is correct |
36 |
Correct |
38 ms |
71176 KB |
Output is correct |
37 |
Correct |
35 ms |
71176 KB |
Output is correct |
38 |
Correct |
36 ms |
71176 KB |
Output is correct |
39 |
Correct |
37 ms |
71176 KB |
Output is correct |
40 |
Correct |
44 ms |
71176 KB |
Output is correct |
41 |
Correct |
194 ms |
71176 KB |
Output is correct |
42 |
Correct |
969 ms |
71176 KB |
Output is correct |
43 |
Correct |
275 ms |
71176 KB |
Output is correct |
44 |
Correct |
410 ms |
71176 KB |
Output is correct |
45 |
Correct |
622 ms |
71176 KB |
Output is correct |
46 |
Correct |
519 ms |
71176 KB |
Output is correct |
47 |
Correct |
611 ms |
71176 KB |
Output is correct |
48 |
Correct |
369 ms |
71176 KB |
Output is correct |
49 |
Correct |
524 ms |
71176 KB |
Output is correct |
50 |
Correct |
585 ms |
71176 KB |
Output is correct |
51 |
Correct |
276 ms |
71176 KB |
Output is correct |
52 |
Correct |
373 ms |
71176 KB |
Output is correct |
53 |
Correct |
334 ms |
71176 KB |
Output is correct |
54 |
Correct |
1661 ms |
71176 KB |
Output is correct |
55 |
Correct |
656 ms |
71176 KB |
Output is correct |