#include <bits/stdc++.h>
using namespace std;
class dsu {
public:
vector<int> p, sz, deg;
bool ans;
void init(int n) {
p.resize(n);
sz.resize(n);
deg.resize(n);
ans = true;
for (int i = 0; i < n; ++i) {
p[i] = i;
sz[i] = 1;
deg[i] = 0;
}
}
inline int find(int x) {
while (x != p[x]) {
x = p[x] = p[p[x]];
}
return x;
}
void unite(int x, int y) {
++deg[x];
++deg[y];
if (deg[x] == 3 || deg[y] == 3) {
ans = false;
}
x = find(x);
y = find(y);
if (x == y) {
ans = false;
} else {
p[x] = y;
sz[y] += sz[x];
}
}
};
vector<pair<int, int>> edges;
vector<int> ban(4, -1);
int n, ans, cycles;
vector<dsu> f(5);
bool stage;
void Init(int N) {
n = N;
for (int i = 0; i < 5; ++i) {
f[i].init(N);
}
}
void Link(int A, int B) {
edges.emplace_back(A, B);
if (!stage) {
if (cycles > 1) {
return;
}
if (f[4].deg[A] < f[4].deg[B]) {
swap(A, B);
}
++f[4].deg[A];
++f[4].deg[B];
if (f[4].deg[A] == 3) {
int ptr = 0;
ban[ptr++] = A;
for (auto p : edges) {
if (p.first == A) {
ban[ptr++] = p.second;
}
if (p.second == A) {
ban[ptr++] = p.first;
}
if (ptr == 4) {
break;
}
}
for (int i = 0; i < 4; ++i) {
for (auto p : edges) {
if (p.first != ban[i] && p.second != ban[i]) {
f[i].unite(p.first, p.second);
}
}
}
stage = true;
return;
}
int a = f[4].find(A), b = f[4].find(B);
if (a == b) {
++cycles;
ans = f[4].sz[a];
} else {
f[4].p[a] = b;
f[4].sz[b] += f[4].sz[a];
}
} else {
for (int i = 0; i < 4; ++i) {
if (A != ban[i] && B != ban[i]) {
f[i].unite(A, B);
}
}
}
}
int CountCritical() {
if (!stage) {
if (cycles == 0) {
return n;
} else if (cycles == 1) {
return ans;
} else {
return 0;
}
} else {
int ans = 0;
for (int i = 0; i < 4; ++i) {
if (f[i].ans) {
++ans;
}
}
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
4 ms |
768 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
4 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
304 ms |
35220 KB |
Output is correct |
2 |
Correct |
1850 ms |
56064 KB |
Output is correct |
3 |
Correct |
3024 ms |
79432 KB |
Output is correct |
4 |
Correct |
857 ms |
80648 KB |
Output is correct |
5 |
Correct |
916 ms |
80728 KB |
Output is correct |
6 |
Correct |
826 ms |
79528 KB |
Output is correct |
7 |
Correct |
2843 ms |
78624 KB |
Output is correct |
8 |
Correct |
2183 ms |
75480 KB |
Output is correct |
9 |
Correct |
2052 ms |
80536 KB |
Output is correct |
10 |
Correct |
575 ms |
79604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
4 ms |
768 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
4 ms |
896 KB |
Output is correct |
11 |
Correct |
6 ms |
768 KB |
Output is correct |
12 |
Correct |
8 ms |
1280 KB |
Output is correct |
13 |
Correct |
7 ms |
1280 KB |
Output is correct |
14 |
Correct |
7 ms |
1152 KB |
Output is correct |
15 |
Correct |
8 ms |
1792 KB |
Output is correct |
16 |
Correct |
7 ms |
1280 KB |
Output is correct |
17 |
Correct |
7 ms |
1280 KB |
Output is correct |
18 |
Correct |
9 ms |
1916 KB |
Output is correct |
19 |
Correct |
6 ms |
1252 KB |
Output is correct |
20 |
Correct |
6 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
4 ms |
768 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
4 ms |
896 KB |
Output is correct |
11 |
Correct |
6 ms |
768 KB |
Output is correct |
12 |
Correct |
8 ms |
1280 KB |
Output is correct |
13 |
Correct |
7 ms |
1280 KB |
Output is correct |
14 |
Correct |
7 ms |
1152 KB |
Output is correct |
15 |
Correct |
8 ms |
1792 KB |
Output is correct |
16 |
Correct |
7 ms |
1280 KB |
Output is correct |
17 |
Correct |
7 ms |
1280 KB |
Output is correct |
18 |
Correct |
9 ms |
1916 KB |
Output is correct |
19 |
Correct |
6 ms |
1252 KB |
Output is correct |
20 |
Correct |
6 ms |
1280 KB |
Output is correct |
21 |
Correct |
23 ms |
4172 KB |
Output is correct |
22 |
Correct |
37 ms |
6500 KB |
Output is correct |
23 |
Correct |
41 ms |
7896 KB |
Output is correct |
24 |
Correct |
96 ms |
7288 KB |
Output is correct |
25 |
Correct |
21 ms |
6656 KB |
Output is correct |
26 |
Correct |
58 ms |
7540 KB |
Output is correct |
27 |
Correct |
53 ms |
7668 KB |
Output is correct |
28 |
Correct |
93 ms |
7712 KB |
Output is correct |
29 |
Correct |
53 ms |
7416 KB |
Output is correct |
30 |
Correct |
55 ms |
8252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
4 ms |
768 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
4 ms |
896 KB |
Output is correct |
11 |
Correct |
304 ms |
35220 KB |
Output is correct |
12 |
Correct |
1850 ms |
56064 KB |
Output is correct |
13 |
Correct |
3024 ms |
79432 KB |
Output is correct |
14 |
Correct |
857 ms |
80648 KB |
Output is correct |
15 |
Correct |
916 ms |
80728 KB |
Output is correct |
16 |
Correct |
826 ms |
79528 KB |
Output is correct |
17 |
Correct |
2843 ms |
78624 KB |
Output is correct |
18 |
Correct |
2183 ms |
75480 KB |
Output is correct |
19 |
Correct |
2052 ms |
80536 KB |
Output is correct |
20 |
Correct |
575 ms |
79604 KB |
Output is correct |
21 |
Correct |
6 ms |
768 KB |
Output is correct |
22 |
Correct |
8 ms |
1280 KB |
Output is correct |
23 |
Correct |
7 ms |
1280 KB |
Output is correct |
24 |
Correct |
7 ms |
1152 KB |
Output is correct |
25 |
Correct |
8 ms |
1792 KB |
Output is correct |
26 |
Correct |
7 ms |
1280 KB |
Output is correct |
27 |
Correct |
7 ms |
1280 KB |
Output is correct |
28 |
Correct |
9 ms |
1916 KB |
Output is correct |
29 |
Correct |
6 ms |
1252 KB |
Output is correct |
30 |
Correct |
6 ms |
1280 KB |
Output is correct |
31 |
Correct |
23 ms |
4172 KB |
Output is correct |
32 |
Correct |
37 ms |
6500 KB |
Output is correct |
33 |
Correct |
41 ms |
7896 KB |
Output is correct |
34 |
Correct |
96 ms |
7288 KB |
Output is correct |
35 |
Correct |
21 ms |
6656 KB |
Output is correct |
36 |
Correct |
58 ms |
7540 KB |
Output is correct |
37 |
Correct |
53 ms |
7668 KB |
Output is correct |
38 |
Correct |
93 ms |
7712 KB |
Output is correct |
39 |
Correct |
53 ms |
7416 KB |
Output is correct |
40 |
Correct |
55 ms |
8252 KB |
Output is correct |
41 |
Correct |
212 ms |
37324 KB |
Output is correct |
42 |
Correct |
699 ms |
62216 KB |
Output is correct |
43 |
Correct |
452 ms |
60524 KB |
Output is correct |
44 |
Correct |
1239 ms |
74052 KB |
Output is correct |
45 |
Correct |
1585 ms |
75840 KB |
Output is correct |
46 |
Correct |
569 ms |
67556 KB |
Output is correct |
47 |
Correct |
827 ms |
68644 KB |
Output is correct |
48 |
Correct |
830 ms |
70076 KB |
Output is correct |
49 |
Correct |
578 ms |
77536 KB |
Output is correct |
50 |
Correct |
654 ms |
76376 KB |
Output is correct |
51 |
Correct |
475 ms |
52992 KB |
Output is correct |
52 |
Correct |
1194 ms |
60352 KB |
Output is correct |
53 |
Correct |
1020 ms |
69280 KB |
Output is correct |
54 |
Correct |
1912 ms |
66044 KB |
Output is correct |
55 |
Correct |
2074 ms |
71500 KB |
Output is correct |