#include <vector>
using namespace std;
int n;
vector<int> edge[1000001];
int phase;
int ans;
void Init(int N) {
n = N;
phase = 0;
ans = n;
}
struct _uf {
int par[1000001];
int sz[1000001];
int st;
int disactive;
_uf() {
for (int i = 1; i <= 1000000; ++i) sz[i] = 1;
}
int find(int x) {
if (par[x]) return par[x] = find(par[x]);
return x;
}
int merge(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return 0;
if (sz[x] < sz[y]) swap(x, y);
par[y] = x;
sz[x] += sz[y];
return 1;
}
void disMerge(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
disactive = 1;
return;
}
par[y] = x;
}
void init(int S) {
st = S;
for (int i = 1; i <= n; ++i) {
if (i == S) continue;
for (int j : edge[i]) {
if (j == S) continue;
if (i < j) disMerge(i, j);
if (disactive) return;
}
}
}
} uf[5];
void changePhase(int x) {
phase = 1;
uf[1].init(x);
int T = 1;
for (int i : edge[x]) uf[++T].init(i);
}
void checkDeg(int x) {
if (edge[x].size() < 3) return;
vector<int> ch;
ch.push_back(x);
if (edge[x].size() == 3) {
for (int i : edge[x]) ch.push_back(i);
}
int d = 0;
for (int i = 1; i <= 4; ++i) {
if (uf[i].disactive) { ++d; continue; }
uf[i].disactive = 1;
for (int j : ch) if (uf[i].st == j) { uf[i].disactive = 0; break; }
d += uf[i].disactive;
}
if (d == 4) phase = 2;
}
int cyc = 0;
void Link(int A, int B) {
if (phase == 2) return;
++A; ++B;
edge[A].push_back(B);
edge[B].push_back(A);
int iniPhase = phase;
if (phase == 0) {
if (edge[A].size() > 2) changePhase(A);
else if (edge[B].size() > 2) changePhase(B);
else {
if (!uf[0].merge(A, B)) {
if (cyc++ == 0) ans = uf[0].sz[uf[0].find(A)];
else phase = 2;
}
}
}
if (phase == 1) checkDeg(A);
if (phase == 1) checkDeg(B);
if (phase == 1 && iniPhase == 1) {
for (int i = 1; i <= 4; ++i) {
if (A == uf[i].st || B == uf[i].st) continue;
uf[i].disMerge(A, B);
}
int d = 0;
for (int i = 1; i <= 4; ++i) d += uf[i].disactive;
if (d == 4) phase = 2;
}
}
int CountCritical() {
if (phase == 0) return ans;
if (phase == 1) {
int ret = 0;
for (int i = 1; i <= 4; ++i) {
if (uf[i].disactive) continue;
++ret;
}
return ret;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
43384 KB |
Output is correct |
2 |
Correct |
40 ms |
43636 KB |
Output is correct |
3 |
Correct |
38 ms |
43672 KB |
Output is correct |
4 |
Correct |
37 ms |
43672 KB |
Output is correct |
5 |
Correct |
49 ms |
43672 KB |
Output is correct |
6 |
Correct |
41 ms |
43672 KB |
Output is correct |
7 |
Correct |
39 ms |
43764 KB |
Output is correct |
8 |
Correct |
39 ms |
43764 KB |
Output is correct |
9 |
Correct |
44 ms |
43836 KB |
Output is correct |
10 |
Correct |
41 ms |
43836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
463 ms |
62080 KB |
Output is correct |
2 |
Correct |
1378 ms |
84688 KB |
Output is correct |
3 |
Correct |
368 ms |
84688 KB |
Output is correct |
4 |
Correct |
1232 ms |
84688 KB |
Output is correct |
5 |
Correct |
1292 ms |
84688 KB |
Output is correct |
6 |
Correct |
1273 ms |
84688 KB |
Output is correct |
7 |
Correct |
345 ms |
84688 KB |
Output is correct |
8 |
Correct |
1838 ms |
91260 KB |
Output is correct |
9 |
Correct |
1880 ms |
94588 KB |
Output is correct |
10 |
Correct |
864 ms |
94588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
43384 KB |
Output is correct |
2 |
Correct |
40 ms |
43636 KB |
Output is correct |
3 |
Correct |
38 ms |
43672 KB |
Output is correct |
4 |
Correct |
37 ms |
43672 KB |
Output is correct |
5 |
Correct |
49 ms |
43672 KB |
Output is correct |
6 |
Correct |
41 ms |
43672 KB |
Output is correct |
7 |
Correct |
39 ms |
43764 KB |
Output is correct |
8 |
Correct |
39 ms |
43764 KB |
Output is correct |
9 |
Correct |
44 ms |
43836 KB |
Output is correct |
10 |
Correct |
41 ms |
43836 KB |
Output is correct |
11 |
Correct |
42 ms |
94588 KB |
Output is correct |
12 |
Correct |
45 ms |
94588 KB |
Output is correct |
13 |
Correct |
45 ms |
94588 KB |
Output is correct |
14 |
Correct |
43 ms |
94588 KB |
Output is correct |
15 |
Correct |
46 ms |
94588 KB |
Output is correct |
16 |
Correct |
42 ms |
94588 KB |
Output is correct |
17 |
Correct |
39 ms |
94588 KB |
Output is correct |
18 |
Correct |
42 ms |
94588 KB |
Output is correct |
19 |
Correct |
43 ms |
94588 KB |
Output is correct |
20 |
Correct |
45 ms |
94588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
43384 KB |
Output is correct |
2 |
Correct |
40 ms |
43636 KB |
Output is correct |
3 |
Correct |
38 ms |
43672 KB |
Output is correct |
4 |
Correct |
37 ms |
43672 KB |
Output is correct |
5 |
Correct |
49 ms |
43672 KB |
Output is correct |
6 |
Correct |
41 ms |
43672 KB |
Output is correct |
7 |
Correct |
39 ms |
43764 KB |
Output is correct |
8 |
Correct |
39 ms |
43764 KB |
Output is correct |
9 |
Correct |
44 ms |
43836 KB |
Output is correct |
10 |
Correct |
41 ms |
43836 KB |
Output is correct |
11 |
Correct |
42 ms |
94588 KB |
Output is correct |
12 |
Correct |
45 ms |
94588 KB |
Output is correct |
13 |
Correct |
45 ms |
94588 KB |
Output is correct |
14 |
Correct |
43 ms |
94588 KB |
Output is correct |
15 |
Correct |
46 ms |
94588 KB |
Output is correct |
16 |
Correct |
42 ms |
94588 KB |
Output is correct |
17 |
Correct |
39 ms |
94588 KB |
Output is correct |
18 |
Correct |
42 ms |
94588 KB |
Output is correct |
19 |
Correct |
43 ms |
94588 KB |
Output is correct |
20 |
Correct |
45 ms |
94588 KB |
Output is correct |
21 |
Correct |
61 ms |
94588 KB |
Output is correct |
22 |
Correct |
75 ms |
94588 KB |
Output is correct |
23 |
Correct |
82 ms |
94588 KB |
Output is correct |
24 |
Correct |
105 ms |
94588 KB |
Output is correct |
25 |
Correct |
55 ms |
94588 KB |
Output is correct |
26 |
Correct |
85 ms |
94588 KB |
Output is correct |
27 |
Correct |
92 ms |
94588 KB |
Output is correct |
28 |
Correct |
68 ms |
94588 KB |
Output is correct |
29 |
Correct |
69 ms |
94588 KB |
Output is correct |
30 |
Correct |
101 ms |
94588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
43384 KB |
Output is correct |
2 |
Correct |
40 ms |
43636 KB |
Output is correct |
3 |
Correct |
38 ms |
43672 KB |
Output is correct |
4 |
Correct |
37 ms |
43672 KB |
Output is correct |
5 |
Correct |
49 ms |
43672 KB |
Output is correct |
6 |
Correct |
41 ms |
43672 KB |
Output is correct |
7 |
Correct |
39 ms |
43764 KB |
Output is correct |
8 |
Correct |
39 ms |
43764 KB |
Output is correct |
9 |
Correct |
44 ms |
43836 KB |
Output is correct |
10 |
Correct |
41 ms |
43836 KB |
Output is correct |
11 |
Correct |
463 ms |
62080 KB |
Output is correct |
12 |
Correct |
1378 ms |
84688 KB |
Output is correct |
13 |
Correct |
368 ms |
84688 KB |
Output is correct |
14 |
Correct |
1232 ms |
84688 KB |
Output is correct |
15 |
Correct |
1292 ms |
84688 KB |
Output is correct |
16 |
Correct |
1273 ms |
84688 KB |
Output is correct |
17 |
Correct |
345 ms |
84688 KB |
Output is correct |
18 |
Correct |
1838 ms |
91260 KB |
Output is correct |
19 |
Correct |
1880 ms |
94588 KB |
Output is correct |
20 |
Correct |
864 ms |
94588 KB |
Output is correct |
21 |
Correct |
42 ms |
94588 KB |
Output is correct |
22 |
Correct |
45 ms |
94588 KB |
Output is correct |
23 |
Correct |
45 ms |
94588 KB |
Output is correct |
24 |
Correct |
43 ms |
94588 KB |
Output is correct |
25 |
Correct |
46 ms |
94588 KB |
Output is correct |
26 |
Correct |
42 ms |
94588 KB |
Output is correct |
27 |
Correct |
39 ms |
94588 KB |
Output is correct |
28 |
Correct |
42 ms |
94588 KB |
Output is correct |
29 |
Correct |
43 ms |
94588 KB |
Output is correct |
30 |
Correct |
45 ms |
94588 KB |
Output is correct |
31 |
Correct |
61 ms |
94588 KB |
Output is correct |
32 |
Correct |
75 ms |
94588 KB |
Output is correct |
33 |
Correct |
82 ms |
94588 KB |
Output is correct |
34 |
Correct |
105 ms |
94588 KB |
Output is correct |
35 |
Correct |
55 ms |
94588 KB |
Output is correct |
36 |
Correct |
85 ms |
94588 KB |
Output is correct |
37 |
Correct |
92 ms |
94588 KB |
Output is correct |
38 |
Correct |
68 ms |
94588 KB |
Output is correct |
39 |
Correct |
69 ms |
94588 KB |
Output is correct |
40 |
Correct |
101 ms |
94588 KB |
Output is correct |
41 |
Correct |
260 ms |
94588 KB |
Output is correct |
42 |
Correct |
705 ms |
94588 KB |
Output is correct |
43 |
Correct |
350 ms |
94588 KB |
Output is correct |
44 |
Correct |
380 ms |
94588 KB |
Output is correct |
45 |
Correct |
468 ms |
94588 KB |
Output is correct |
46 |
Correct |
779 ms |
94588 KB |
Output is correct |
47 |
Correct |
1032 ms |
94588 KB |
Output is correct |
48 |
Correct |
368 ms |
94588 KB |
Output is correct |
49 |
Correct |
772 ms |
94588 KB |
Output is correct |
50 |
Correct |
829 ms |
94588 KB |
Output is correct |
51 |
Correct |
383 ms |
94588 KB |
Output is correct |
52 |
Correct |
353 ms |
94588 KB |
Output is correct |
53 |
Correct |
282 ms |
94588 KB |
Output is correct |
54 |
Correct |
1453 ms |
94588 KB |
Output is correct |
55 |
Correct |
1463 ms |
94588 KB |
Output is correct |