#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 < 3; ++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 |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
3 ms |
680 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
348 ms |
42084 KB |
Output is correct |
2 |
Incorrect |
1370 ms |
64688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
3 ms |
680 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
3 ms |
680 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
3 ms |
680 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |