#include<cstdio>
#include<vector>
using namespace std;
const int SZ = 1000010;
int min(int a, int b) { return a < b ? a : b; }
int n;
const bool ifDebug = false;
int cycleNum;
vector<vector<int>>l;
typedef struct Graph {
int st[4], ts[3];
int p[SZ], sz[SZ], cs[SZ][4], c[SZ];
int x;
bool isMain;
void init() {
x = n;
isMain = true;
st[0] = ts[0] = n;
st[1] = st[2] = st[3] = ts[1] = ts[2] = 0;
for (int i = 0; i < n; i++) {
p[i] = i;
cs[i][0] = sz[i] = 1;
cs[i][1] = cs[i][2] = cs[i][3] = c[i] = 0;
}
}
void init(int X) {
if(ifDebug)printf("init(%d)\n", X);
init();
isMain = false;
x = X;
PR();
for (int i = 0; i < n; i++) {
for (int e : l[i]) {
if (e < i)Link(e, i);
}
}
}
int f(int a) {
return a == p[a] ? a : p[a] = f(p[a]);
}
void u(int A, int B) {
int a = f(A), b = f(B);
if (a != b) {
p[b] = a;
ts[gT(a)]--;
ts[gT(b)]--;
for (int i = 0; i < 4; i++) {
cs[a][i] += cs[b][i];
}
sz[a] += sz[b];
}
else {
ts[gT(a)]--;
}
}
void Con(int A, int B) {
int a = f(A);
cs[a][min(c[A], 3)]--;
st[min(c[A], 3)]--;
if(isMain)l[A].push_back(B);
c[A]++;
cs[a][min(c[A], 3)]++;
st[min(c[A], 3)]++;
}
int gT(int a) {
if (cs[a][3]) {
return 2;
}
else if (cs[a][2] && (cs[a][1] + cs[a][0] == 0)) {
return 1;
}
else {
return 0;
}
}
void Link(int A, int B) {
if (A == x || B == x)return;
if (ifDebug)printf("%d:%d-%d\n", x, A, B);
u(A, B);
Con(A, B);
Con(B, A);
int a = f(A);
ts[gT(a)]++;
}
bool isChain() {
return (ts[1] + ts[2] == 0);
}
void PR() {
if (!ifDebug)return;
printf("-------%d-------\n", x);
for (int a = 0; a < n; a++) {
printf("(%d)", c[a]);
if (a == p[a]) {
printf("[%d(%d,%d)]", a, sz[a], gT(a));
for (int b = 0; b < 4; b++)printf(" %d", cs[a][b]);
printf("\n");
}
else {
printf("%d->%d\n", a, f(a));
}
}
printf("-----------------\n");
}
}Graph;
Graph MG, GV[4];
int GS;
//type: 0-chain/1-cycle/2-3 exists/3-4 exists
void Init(int N) {
l.resize(N);
cycleNum = n = N;
MG.init();
}
void Link(int A, int B) {
bool p = (MG.st[3] == 0);
MG.Link(A, B);
for (int i = 0; i < GS; i++) {
GV[i].Link(A, B);
}
if (MG.gT(MG.f(A)) == 1)cycleNum = MG.f(A);
if (MG.gT(MG.f(B)) == 1)cycleNum = MG.f(B);
if (p && MG.st[3]) {
if (ifDebug)printf("걸렸구나!!!!!!!!!\n");
int a = A;
if (l[A].size() < 3)a = B;
GV[GS++].init(a);
//return;
for (int e : l[a]) {
GV[GS++].init(e);
}
}
}
int CountCritical() {
if (MG.ts[2]) {
if (ifDebug)printf(">=3 Exists");
int r = 0;
for (int i = 0; i < GS; i++) {
if (GV[i].isChain())r++;
}
return r;
}
else if (MG.ts[1]) {
if (ifDebug)printf("cycle Exists");
if (MG.ts[1] > 1)return 0;
return MG.sz[cycleNum];
}
else {
if (ifDebug)printf("Already Chain");
return n;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
4 ms |
1216 KB |
Output is correct |
3 |
Correct |
5 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
3 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
5 ms |
1412 KB |
Output is correct |
10 |
Correct |
5 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
556 ms |
43032 KB |
Output is correct |
2 |
Correct |
2655 ms |
153904 KB |
Output is correct |
3 |
Correct |
3634 ms |
190188 KB |
Output is correct |
4 |
Correct |
1422 ms |
95744 KB |
Output is correct |
5 |
Correct |
1391 ms |
96000 KB |
Output is correct |
6 |
Correct |
1357 ms |
94124 KB |
Output is correct |
7 |
Correct |
3465 ms |
199644 KB |
Output is correct |
8 |
Correct |
3069 ms |
192256 KB |
Output is correct |
9 |
Correct |
3306 ms |
205296 KB |
Output is correct |
10 |
Correct |
996 ms |
94096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
4 ms |
1216 KB |
Output is correct |
3 |
Correct |
5 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
3 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
5 ms |
1412 KB |
Output is correct |
10 |
Correct |
5 ms |
1356 KB |
Output is correct |
11 |
Correct |
5 ms |
1356 KB |
Output is correct |
12 |
Correct |
9 ms |
2400 KB |
Output is correct |
13 |
Correct |
10 ms |
2380 KB |
Output is correct |
14 |
Correct |
7 ms |
2188 KB |
Output is correct |
15 |
Correct |
11 ms |
3788 KB |
Output is correct |
16 |
Correct |
8 ms |
1148 KB |
Output is correct |
17 |
Correct |
9 ms |
2380 KB |
Output is correct |
18 |
Correct |
12 ms |
4112 KB |
Output is correct |
19 |
Correct |
5 ms |
1100 KB |
Output is correct |
20 |
Correct |
11 ms |
2400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
4 ms |
1216 KB |
Output is correct |
3 |
Correct |
5 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
3 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
5 ms |
1412 KB |
Output is correct |
10 |
Correct |
5 ms |
1356 KB |
Output is correct |
11 |
Correct |
5 ms |
1356 KB |
Output is correct |
12 |
Correct |
9 ms |
2400 KB |
Output is correct |
13 |
Correct |
10 ms |
2380 KB |
Output is correct |
14 |
Correct |
7 ms |
2188 KB |
Output is correct |
15 |
Correct |
11 ms |
3788 KB |
Output is correct |
16 |
Correct |
8 ms |
1148 KB |
Output is correct |
17 |
Correct |
9 ms |
2380 KB |
Output is correct |
18 |
Correct |
12 ms |
4112 KB |
Output is correct |
19 |
Correct |
5 ms |
1100 KB |
Output is correct |
20 |
Correct |
11 ms |
2400 KB |
Output is correct |
21 |
Correct |
21 ms |
3892 KB |
Output is correct |
22 |
Correct |
36 ms |
5944 KB |
Output is correct |
23 |
Correct |
51 ms |
7492 KB |
Output is correct |
24 |
Correct |
133 ms |
16836 KB |
Output is correct |
25 |
Correct |
31 ms |
16660 KB |
Output is correct |
26 |
Correct |
122 ms |
17764 KB |
Output is correct |
27 |
Correct |
55 ms |
7236 KB |
Output is correct |
28 |
Correct |
162 ms |
17368 KB |
Output is correct |
29 |
Correct |
91 ms |
18132 KB |
Output is correct |
30 |
Correct |
78 ms |
8400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
4 ms |
1216 KB |
Output is correct |
3 |
Correct |
5 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
3 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
5 ms |
1412 KB |
Output is correct |
10 |
Correct |
5 ms |
1356 KB |
Output is correct |
11 |
Correct |
556 ms |
43032 KB |
Output is correct |
12 |
Correct |
2655 ms |
153904 KB |
Output is correct |
13 |
Correct |
3634 ms |
190188 KB |
Output is correct |
14 |
Correct |
1422 ms |
95744 KB |
Output is correct |
15 |
Correct |
1391 ms |
96000 KB |
Output is correct |
16 |
Correct |
1357 ms |
94124 KB |
Output is correct |
17 |
Correct |
3465 ms |
199644 KB |
Output is correct |
18 |
Correct |
3069 ms |
192256 KB |
Output is correct |
19 |
Correct |
3306 ms |
205296 KB |
Output is correct |
20 |
Correct |
996 ms |
94096 KB |
Output is correct |
21 |
Correct |
5 ms |
1356 KB |
Output is correct |
22 |
Correct |
9 ms |
2400 KB |
Output is correct |
23 |
Correct |
10 ms |
2380 KB |
Output is correct |
24 |
Correct |
7 ms |
2188 KB |
Output is correct |
25 |
Correct |
11 ms |
3788 KB |
Output is correct |
26 |
Correct |
8 ms |
1148 KB |
Output is correct |
27 |
Correct |
9 ms |
2380 KB |
Output is correct |
28 |
Correct |
12 ms |
4112 KB |
Output is correct |
29 |
Correct |
5 ms |
1100 KB |
Output is correct |
30 |
Correct |
11 ms |
2400 KB |
Output is correct |
31 |
Correct |
21 ms |
3892 KB |
Output is correct |
32 |
Correct |
36 ms |
5944 KB |
Output is correct |
33 |
Correct |
51 ms |
7492 KB |
Output is correct |
34 |
Correct |
133 ms |
16836 KB |
Output is correct |
35 |
Correct |
31 ms |
16660 KB |
Output is correct |
36 |
Correct |
122 ms |
17764 KB |
Output is correct |
37 |
Correct |
55 ms |
7236 KB |
Output is correct |
38 |
Correct |
162 ms |
17368 KB |
Output is correct |
39 |
Correct |
91 ms |
18132 KB |
Output is correct |
40 |
Correct |
78 ms |
8400 KB |
Output is correct |
41 |
Correct |
268 ms |
37768 KB |
Output is correct |
42 |
Correct |
1322 ms |
157656 KB |
Output is correct |
43 |
Correct |
490 ms |
155856 KB |
Output is correct |
44 |
Correct |
2196 ms |
188760 KB |
Output is correct |
45 |
Correct |
2482 ms |
189380 KB |
Output is correct |
46 |
Correct |
923 ms |
79980 KB |
Output is correct |
47 |
Correct |
1193 ms |
81304 KB |
Output is correct |
48 |
Correct |
1226 ms |
183584 KB |
Output is correct |
49 |
Correct |
906 ms |
87132 KB |
Output is correct |
50 |
Correct |
953 ms |
86236 KB |
Output is correct |
51 |
Correct |
640 ms |
136136 KB |
Output is correct |
52 |
Correct |
1933 ms |
151580 KB |
Output is correct |
53 |
Correct |
1310 ms |
183832 KB |
Output is correct |
54 |
Correct |
2668 ms |
165992 KB |
Output is correct |
55 |
Correct |
3023 ms |
181268 KB |
Output is correct |