int n, cyc, Res;
int E[1010000][3], deg[5][1010000], chk[5], Num[5];
int par[5][1010000], SZ[1010000];
void Init(int N_) {
n = N_;
Res = n;
int i;
for (i = 1; i <= n; i++)SZ[i] = 1, par[0][i] = i;
}
int Find(int ck, int a){
if (par[ck][a] == a)return a;
return par[ck][a] = Find(ck, par[ck][a]);
}
void Add(int ck, int a, int b){
if (chk[ck])return;
if (ck && (Num[ck] == a || Num[ck] == b))return;
if (!ck){
E[a][deg[0][a]] = b, E[b][deg[0][b]] = a;
}
deg[ck][a]++, deg[ck][b]++;
if (ck && (deg[ck][a] >= 3 || deg[ck][b] >= 3)){
chk[ck] = 1;
return;
}
a = Find(ck, a), b = Find(ck, b);
if (a == b){
if (!ck){
cyc++;
if (cyc == 1)Res = SZ[a];
}
else chk[ck] = 1;
}
else{
par[ck][a] = b;
if (!ck){
SZ[b] += SZ[a];
SZ[a] = 0;
}
}
}
void Make(int a){
int i, j, k, x;
Num[1] = a;
for (i = 0; i < 3; i++){
Num[2 + i] = E[a][i];
}
chk[0] = 1;
for (k = 1; k <= 4; k++){
for (i = 1; i <= n; i++)par[k][i] = i;
for (i = 1; i <= n; i++){
for (j = 0; j < deg[0][i]; j++){
x = E[i][j];
if (i == Num[k] || x == Num[k] || x > i)continue;
Add(k, i, x);
}
}
}
}
void Link(int A, int B) {
if (!Res)return;
A++, B++;
if (!chk[0]){
if (cyc == 2)Res = 0;
Add(0, A, B);
if (deg[0][A] == 3){
Make(A);
}
else if (deg[0][B] == 3){
Make(B);
}
}
else{
int i;
for (i = 1; i <= 4; i++)Add(i, A, B);
}
}
int CountCritical() {
if (!chk[0]){
if (cyc == 2)Res = 0;
return Res;
}
int i, r = 0;
for (i = 1; i <= 4; i++)if (!chk[i])r++;
return r;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
664 KB |
Output is correct |
3 |
Correct |
4 ms |
808 KB |
Output is correct |
4 |
Correct |
2 ms |
808 KB |
Output is correct |
5 |
Correct |
3 ms |
808 KB |
Output is correct |
6 |
Correct |
3 ms |
808 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
318 ms |
12864 KB |
Output is correct |
2 |
Correct |
587 ms |
44628 KB |
Output is correct |
3 |
Correct |
381 ms |
55252 KB |
Output is correct |
4 |
Correct |
865 ms |
55252 KB |
Output is correct |
5 |
Correct |
842 ms |
55252 KB |
Output is correct |
6 |
Correct |
827 ms |
55252 KB |
Output is correct |
7 |
Correct |
349 ms |
55380 KB |
Output is correct |
8 |
Correct |
927 ms |
55380 KB |
Output is correct |
9 |
Correct |
1111 ms |
55380 KB |
Output is correct |
10 |
Correct |
630 ms |
55380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
664 KB |
Output is correct |
3 |
Correct |
4 ms |
808 KB |
Output is correct |
4 |
Correct |
2 ms |
808 KB |
Output is correct |
5 |
Correct |
3 ms |
808 KB |
Output is correct |
6 |
Correct |
3 ms |
808 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
4 ms |
55380 KB |
Output is correct |
12 |
Correct |
11 ms |
55380 KB |
Output is correct |
13 |
Correct |
6 ms |
55380 KB |
Output is correct |
14 |
Correct |
4 ms |
55380 KB |
Output is correct |
15 |
Correct |
5 ms |
55380 KB |
Output is correct |
16 |
Correct |
5 ms |
55380 KB |
Output is correct |
17 |
Correct |
6 ms |
55380 KB |
Output is correct |
18 |
Correct |
6 ms |
55380 KB |
Output is correct |
19 |
Correct |
5 ms |
55380 KB |
Output is correct |
20 |
Correct |
7 ms |
55380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
664 KB |
Output is correct |
3 |
Correct |
4 ms |
808 KB |
Output is correct |
4 |
Correct |
2 ms |
808 KB |
Output is correct |
5 |
Correct |
3 ms |
808 KB |
Output is correct |
6 |
Correct |
3 ms |
808 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
4 ms |
55380 KB |
Output is correct |
12 |
Correct |
11 ms |
55380 KB |
Output is correct |
13 |
Correct |
6 ms |
55380 KB |
Output is correct |
14 |
Correct |
4 ms |
55380 KB |
Output is correct |
15 |
Correct |
5 ms |
55380 KB |
Output is correct |
16 |
Correct |
5 ms |
55380 KB |
Output is correct |
17 |
Correct |
6 ms |
55380 KB |
Output is correct |
18 |
Correct |
6 ms |
55380 KB |
Output is correct |
19 |
Correct |
5 ms |
55380 KB |
Output is correct |
20 |
Correct |
7 ms |
55380 KB |
Output is correct |
21 |
Correct |
18 ms |
55380 KB |
Output is correct |
22 |
Correct |
30 ms |
55380 KB |
Output is correct |
23 |
Correct |
41 ms |
55380 KB |
Output is correct |
24 |
Correct |
43 ms |
55380 KB |
Output is correct |
25 |
Correct |
18 ms |
55380 KB |
Output is correct |
26 |
Correct |
40 ms |
55380 KB |
Output is correct |
27 |
Correct |
42 ms |
55380 KB |
Output is correct |
28 |
Correct |
39 ms |
55380 KB |
Output is correct |
29 |
Correct |
34 ms |
55380 KB |
Output is correct |
30 |
Correct |
46 ms |
55380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
664 KB |
Output is correct |
3 |
Correct |
4 ms |
808 KB |
Output is correct |
4 |
Correct |
2 ms |
808 KB |
Output is correct |
5 |
Correct |
3 ms |
808 KB |
Output is correct |
6 |
Correct |
3 ms |
808 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
318 ms |
12864 KB |
Output is correct |
12 |
Correct |
587 ms |
44628 KB |
Output is correct |
13 |
Correct |
381 ms |
55252 KB |
Output is correct |
14 |
Correct |
865 ms |
55252 KB |
Output is correct |
15 |
Correct |
842 ms |
55252 KB |
Output is correct |
16 |
Correct |
827 ms |
55252 KB |
Output is correct |
17 |
Correct |
349 ms |
55380 KB |
Output is correct |
18 |
Correct |
927 ms |
55380 KB |
Output is correct |
19 |
Correct |
1111 ms |
55380 KB |
Output is correct |
20 |
Correct |
630 ms |
55380 KB |
Output is correct |
21 |
Correct |
4 ms |
55380 KB |
Output is correct |
22 |
Correct |
11 ms |
55380 KB |
Output is correct |
23 |
Correct |
6 ms |
55380 KB |
Output is correct |
24 |
Correct |
4 ms |
55380 KB |
Output is correct |
25 |
Correct |
5 ms |
55380 KB |
Output is correct |
26 |
Correct |
5 ms |
55380 KB |
Output is correct |
27 |
Correct |
6 ms |
55380 KB |
Output is correct |
28 |
Correct |
6 ms |
55380 KB |
Output is correct |
29 |
Correct |
5 ms |
55380 KB |
Output is correct |
30 |
Correct |
7 ms |
55380 KB |
Output is correct |
31 |
Correct |
18 ms |
55380 KB |
Output is correct |
32 |
Correct |
30 ms |
55380 KB |
Output is correct |
33 |
Correct |
41 ms |
55380 KB |
Output is correct |
34 |
Correct |
43 ms |
55380 KB |
Output is correct |
35 |
Correct |
18 ms |
55380 KB |
Output is correct |
36 |
Correct |
40 ms |
55380 KB |
Output is correct |
37 |
Correct |
42 ms |
55380 KB |
Output is correct |
38 |
Correct |
39 ms |
55380 KB |
Output is correct |
39 |
Correct |
34 ms |
55380 KB |
Output is correct |
40 |
Correct |
46 ms |
55380 KB |
Output is correct |
41 |
Correct |
195 ms |
55380 KB |
Output is correct |
42 |
Correct |
597 ms |
55380 KB |
Output is correct |
43 |
Correct |
245 ms |
55380 KB |
Output is correct |
44 |
Correct |
335 ms |
55380 KB |
Output is correct |
45 |
Correct |
504 ms |
55756 KB |
Output is correct |
46 |
Correct |
637 ms |
55756 KB |
Output is correct |
47 |
Correct |
742 ms |
55756 KB |
Output is correct |
48 |
Correct |
328 ms |
56956 KB |
Output is correct |
49 |
Correct |
616 ms |
56956 KB |
Output is correct |
50 |
Correct |
644 ms |
56956 KB |
Output is correct |
51 |
Correct |
257 ms |
56956 KB |
Output is correct |
52 |
Correct |
334 ms |
56956 KB |
Output is correct |
53 |
Correct |
305 ms |
56956 KB |
Output is correct |
54 |
Correct |
892 ms |
56956 KB |
Output is correct |
55 |
Correct |
502 ms |
56956 KB |
Output is correct |