#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 20;
vector<pair<int, int>> edges;
int deg[4][maxn];
int L[4][maxn];
int R[4][maxn];
int cand[4];
bool good[4];
int n;
void Init(int _n) {
n = _n;
for (int k = 0; k < 4; k++) {
cand[k] = -1;
}
}
void update(int k, int u, int v) {
if (!good[k]) {
return;
}
if (u == cand[k] || v == cand[k]) {
return;
}
if (deg[k][u] == 2 || deg[k][v] == 2) {
good[k] = false;
return;
}
deg[k][u]++;
deg[k][v]++;
int lu = L[k][u];
int ru = R[k][u];
int lv = L[k][v];
int rv = R[k][v];
if (lu == lv) {
good[k] = false;
return;
}
if (lu == u) {
swap(lu, ru);
L[k][lu] = lu;
L[k][ru] = lu;
R[k][lu] = ru;
R[k][ru] = ru;
}
if (rv == v) {
swap(lv, rv);
L[k][lv] = lv;
L[k][rv] = lv;
R[k][lv] = rv;
R[k][rv] = rv;
}
L[k][lu] = lu;
R[k][lu] = rv;
L[k][rv] = lu;
R[k][rv] = rv;
}
void Link(int u, int v) {
if (cand[0] == -1) {
edges.emplace_back(u, v);
deg[0][u]++;
deg[0][v]++;
if (deg[0][v] == 3) {
swap(u, v);
}
if (deg[0][u] == 3) {
cand[0] = u;
int cnt = 0;
for (auto e: edges) {
if (e.first == u) {
cand[++cnt] = e.second;
}
else if (e.second == u) {
cand[++cnt] = e.first;
}
}
for (int k = 0; k < 4; k++) {
good[k] = true;
for (int i = 0; i < n; i++) {
deg[k][i] = 0;
L[k][i] = i;
R[k][i] = i;
}
}
for (auto e: edges) {
for (int k = 0; k < 4; k++) {
update(k, e.first, e.second);
}
}
edges.clear();
}
}
else {
for (int k = 0; k < 4; k++) {
update(k, u, v);
}
}
}
int CountCritical() {
if (cand[0] == -1) {
return n;
}
else {
return good[0] + good[1] + good[2] + good[3];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
612 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
13364 KB |
Output is correct |
2 |
Correct |
271 ms |
50824 KB |
Output is correct |
3 |
Correct |
167 ms |
60092 KB |
Output is correct |
4 |
Incorrect |
164 ms |
25604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
612 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
612 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
612 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |