#include <bits/stdc++.h>
using namespace std;
struct UF{
int t[1000000];
void init(){
for(int i=0;i<1000000;i++){
t[i]=-1;
}
}
int par(int x){
if(t[x]<0)return x;
return t[x]=par(t[x]);
}
bool uni(int x,int y){
x=par(x);
y=par(y);
if(x==y)return false;
if(t[x]<t[y]){
t[x]+=t[y];
t[y]=x;
}
else{
t[y]+=t[x];
t[x]=y;
}
return true;
}
};
int phase,p[4];
UF uf,up[4];
int c[1000000],res;
bool b[4];
vector<int>e[1000000];
void Init(int N) {
res=N;
uf.init();
for(int i=0;i<4;i++){
up[i].init();
}
}
void Link(int A, int B) {
e[A].push_back(B);
e[B].push_back(A);
if(phase==0){
if(e[A].size()==3){
phase=2;
for(int i=0;i<3;i++){
p[i]=e[A][i];
}
p[3]=A;
for(int i=0;i<4;i++){
b[i]=true;
}
for(int i=0;i<4;i++){
for(int j=0;j<1000000;j++){
if(p[i]==j)continue;
int c=0;
for(int k:e[j]){
if(p[i]==k)continue;
c++;
if(j<k)continue;
if(!up[i].uni(j,k)){
b[i]=false;
}
}
if(c>=3)b[i]=false;
}
}
}
else if(e[B].size()==3){
phase=2;
for(int i=0;i<3;i++){
p[i]=e[B][i];
}
p[3]=B;
for(int i=0;i<4;i++){
b[i]=true;
}
for(int i=0;i<4;i++){
for(int j=0;j<1000000;j++){
if(p[i]==j)continue;
int c=0;
for(int k:e[j]){
if(p[i]==k)continue;
c++;
if(j<k)continue;
if(!up[i].uni(j,k)){
b[i]=false;
}
}
if(c>=3)b[i]=false;
}
}
}
else if(!uf.uni(A,B)){
phase=1;
res=-uf.t[uf.par(A)];
}
}
else if(phase==1){
if(e[A].size()==3){
phase=2;
for(int i=0;i<3;i++){
p[i]=e[A][i];
}
p[3]=A;
for(int i=0;i<4;i++){
b[i]=true;
}
for(int i=0;i<4;i++){
for(int j=0;j<1000000;j++){
if(p[i]==j)continue;
int c=0;
for(int k:e[j]){
if(p[i]==k)continue;
c++;
if(j<k)continue;
if(!up[i].uni(j,k)){
b[i]=false;
}
}
if(c>=3)b[i]=false;
}
}
}
else if(e[B].size()==3){
phase=2;
for(int i=0;i<3;i++){
p[i]=e[B][i];
}
p[3]=B;
for(int i=0;i<4;i++){
b[i]=true;
}
for(int i=0;i<4;i++){
for(int j=0;j<1000000;j++){
if(p[i]==j)continue;
int c=0;
for(int k:e[j]){
if(p[i]==k)continue;
c++;
if(j<k)continue;
if(!up[i].uni(j,k)){
b[i]=false;
}
}
if(c>=3)b[i]=false;
}
}
}
else if(!uf.uni(A,B)){
phase=3;
}
}
else if(phase==2){
for(int i=0;i<4;i++){
if(!b[i])continue;
if(A!=p[i]&&B!=p[i]){
if(!up[i].uni(A,B)){
b[i]=false;
}
int c=0;
for(int j:e[A]){
if(j!=p[i])c++;
}
if(c>=3)b[i]=false;
c=0;
for(int j:e[B]){
if(j!=p[i])c++;
}
if(c>=3)b[i]=false;
}
}
}
}
int CountCritical() {
if(phase==0)return res;
if(phase==1)return res;
if(phase==2){
res=0;
for(int i=0;i<4;i++){
res+=b[i];
}
return res;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
43384 KB |
Output is correct |
2 |
Correct |
38 ms |
43520 KB |
Output is correct |
3 |
Correct |
43 ms |
43640 KB |
Output is correct |
4 |
Correct |
27 ms |
43392 KB |
Output is correct |
5 |
Correct |
33 ms |
43520 KB |
Output is correct |
6 |
Correct |
29 ms |
43640 KB |
Output is correct |
7 |
Correct |
35 ms |
43384 KB |
Output is correct |
8 |
Correct |
29 ms |
43520 KB |
Output is correct |
9 |
Correct |
43 ms |
43640 KB |
Output is correct |
10 |
Correct |
38 ms |
43640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
478 ms |
66536 KB |
Output is correct |
2 |
Correct |
1102 ms |
79208 KB |
Output is correct |
3 |
Correct |
955 ms |
83544 KB |
Output is correct |
4 |
Correct |
1176 ms |
88184 KB |
Output is correct |
5 |
Correct |
1166 ms |
88440 KB |
Output is correct |
6 |
Correct |
1122 ms |
86776 KB |
Output is correct |
7 |
Correct |
917 ms |
82552 KB |
Output is correct |
8 |
Correct |
1586 ms |
85440 KB |
Output is correct |
9 |
Correct |
1633 ms |
88104 KB |
Output is correct |
10 |
Correct |
766 ms |
85660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
43384 KB |
Output is correct |
2 |
Correct |
38 ms |
43520 KB |
Output is correct |
3 |
Correct |
43 ms |
43640 KB |
Output is correct |
4 |
Correct |
27 ms |
43392 KB |
Output is correct |
5 |
Correct |
33 ms |
43520 KB |
Output is correct |
6 |
Correct |
29 ms |
43640 KB |
Output is correct |
7 |
Correct |
35 ms |
43384 KB |
Output is correct |
8 |
Correct |
29 ms |
43520 KB |
Output is correct |
9 |
Correct |
43 ms |
43640 KB |
Output is correct |
10 |
Correct |
38 ms |
43640 KB |
Output is correct |
11 |
Correct |
39 ms |
43640 KB |
Output is correct |
12 |
Correct |
45 ms |
43776 KB |
Output is correct |
13 |
Correct |
46 ms |
43776 KB |
Output is correct |
14 |
Correct |
45 ms |
43684 KB |
Output is correct |
15 |
Correct |
43 ms |
43640 KB |
Output is correct |
16 |
Correct |
37 ms |
43776 KB |
Output is correct |
17 |
Correct |
39 ms |
43768 KB |
Output is correct |
18 |
Correct |
39 ms |
44024 KB |
Output is correct |
19 |
Correct |
31 ms |
43840 KB |
Output is correct |
20 |
Correct |
42 ms |
43768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
43384 KB |
Output is correct |
2 |
Correct |
38 ms |
43520 KB |
Output is correct |
3 |
Correct |
43 ms |
43640 KB |
Output is correct |
4 |
Correct |
27 ms |
43392 KB |
Output is correct |
5 |
Correct |
33 ms |
43520 KB |
Output is correct |
6 |
Correct |
29 ms |
43640 KB |
Output is correct |
7 |
Correct |
35 ms |
43384 KB |
Output is correct |
8 |
Correct |
29 ms |
43520 KB |
Output is correct |
9 |
Correct |
43 ms |
43640 KB |
Output is correct |
10 |
Correct |
38 ms |
43640 KB |
Output is correct |
11 |
Correct |
39 ms |
43640 KB |
Output is correct |
12 |
Correct |
45 ms |
43776 KB |
Output is correct |
13 |
Correct |
46 ms |
43776 KB |
Output is correct |
14 |
Correct |
45 ms |
43684 KB |
Output is correct |
15 |
Correct |
43 ms |
43640 KB |
Output is correct |
16 |
Correct |
37 ms |
43776 KB |
Output is correct |
17 |
Correct |
39 ms |
43768 KB |
Output is correct |
18 |
Correct |
39 ms |
44024 KB |
Output is correct |
19 |
Correct |
31 ms |
43840 KB |
Output is correct |
20 |
Correct |
42 ms |
43768 KB |
Output is correct |
21 |
Correct |
46 ms |
44792 KB |
Output is correct |
22 |
Correct |
65 ms |
45688 KB |
Output is correct |
23 |
Correct |
77 ms |
46304 KB |
Output is correct |
24 |
Correct |
90 ms |
45868 KB |
Output is correct |
25 |
Correct |
52 ms |
43896 KB |
Output is correct |
26 |
Correct |
80 ms |
46456 KB |
Output is correct |
27 |
Correct |
81 ms |
47224 KB |
Output is correct |
28 |
Correct |
87 ms |
47224 KB |
Output is correct |
29 |
Correct |
78 ms |
45560 KB |
Output is correct |
30 |
Correct |
110 ms |
47608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
43384 KB |
Output is correct |
2 |
Correct |
38 ms |
43520 KB |
Output is correct |
3 |
Correct |
43 ms |
43640 KB |
Output is correct |
4 |
Correct |
27 ms |
43392 KB |
Output is correct |
5 |
Correct |
33 ms |
43520 KB |
Output is correct |
6 |
Correct |
29 ms |
43640 KB |
Output is correct |
7 |
Correct |
35 ms |
43384 KB |
Output is correct |
8 |
Correct |
29 ms |
43520 KB |
Output is correct |
9 |
Correct |
43 ms |
43640 KB |
Output is correct |
10 |
Correct |
38 ms |
43640 KB |
Output is correct |
11 |
Correct |
478 ms |
66536 KB |
Output is correct |
12 |
Correct |
1102 ms |
79208 KB |
Output is correct |
13 |
Correct |
955 ms |
83544 KB |
Output is correct |
14 |
Correct |
1176 ms |
88184 KB |
Output is correct |
15 |
Correct |
1166 ms |
88440 KB |
Output is correct |
16 |
Correct |
1122 ms |
86776 KB |
Output is correct |
17 |
Correct |
917 ms |
82552 KB |
Output is correct |
18 |
Correct |
1586 ms |
85440 KB |
Output is correct |
19 |
Correct |
1633 ms |
88104 KB |
Output is correct |
20 |
Correct |
766 ms |
85660 KB |
Output is correct |
21 |
Correct |
39 ms |
43640 KB |
Output is correct |
22 |
Correct |
45 ms |
43776 KB |
Output is correct |
23 |
Correct |
46 ms |
43776 KB |
Output is correct |
24 |
Correct |
45 ms |
43684 KB |
Output is correct |
25 |
Correct |
43 ms |
43640 KB |
Output is correct |
26 |
Correct |
37 ms |
43776 KB |
Output is correct |
27 |
Correct |
39 ms |
43768 KB |
Output is correct |
28 |
Correct |
39 ms |
44024 KB |
Output is correct |
29 |
Correct |
31 ms |
43840 KB |
Output is correct |
30 |
Correct |
42 ms |
43768 KB |
Output is correct |
31 |
Correct |
46 ms |
44792 KB |
Output is correct |
32 |
Correct |
65 ms |
45688 KB |
Output is correct |
33 |
Correct |
77 ms |
46304 KB |
Output is correct |
34 |
Correct |
90 ms |
45868 KB |
Output is correct |
35 |
Correct |
52 ms |
43896 KB |
Output is correct |
36 |
Correct |
80 ms |
46456 KB |
Output is correct |
37 |
Correct |
81 ms |
47224 KB |
Output is correct |
38 |
Correct |
87 ms |
47224 KB |
Output is correct |
39 |
Correct |
78 ms |
45560 KB |
Output is correct |
40 |
Correct |
110 ms |
47608 KB |
Output is correct |
41 |
Correct |
280 ms |
55572 KB |
Output is correct |
42 |
Correct |
739 ms |
66424 KB |
Output is correct |
43 |
Correct |
316 ms |
50552 KB |
Output is correct |
44 |
Correct |
671 ms |
83704 KB |
Output is correct |
45 |
Correct |
747 ms |
73688 KB |
Output is correct |
46 |
Correct |
743 ms |
81816 KB |
Output is correct |
47 |
Correct |
992 ms |
82296 KB |
Output is correct |
48 |
Correct |
542 ms |
66424 KB |
Output is correct |
49 |
Correct |
748 ms |
79608 KB |
Output is correct |
50 |
Correct |
783 ms |
79224 KB |
Output is correct |
51 |
Correct |
383 ms |
52500 KB |
Output is correct |
52 |
Correct |
583 ms |
76768 KB |
Output is correct |
53 |
Correct |
485 ms |
66680 KB |
Output is correct |
54 |
Correct |
1301 ms |
80760 KB |
Output is correct |
55 |
Correct |
1051 ms |
83752 KB |
Output is correct |