#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n;
int par[N];
int deg[N];
int visit[N];
int root = -1;
bool inCircle[N];
bool noSolution;
bool checkConnect;
vector<int> G[N];
vector<int> vnode;
vector<int> vcircle;
int find(int u) { return u == par[u] ? u : par[u] = find(par[u]); }
bool join(int u, int v) { u = find(u), v = find(v), par[u] = v; return u != v; }
void Init(int _n) {
n = _n;
for (int i = 0; i < n; ++i) par[i] = i;
}
vector<int> findPath(int A, int B) {
for (int i = 0; i < n; ++i) visit[i] = -1;
queue<int> qu; visit[A] = A, qu.push(A);
while (qu.size()) {
int u = qu.front(); qu.pop();
for (auto v : G[u]) {
if (visit[v] == -1) visit[v] = u, qu.push(v);
}
}
vector<int> path;
int cur = B;
while (cur != A) {
path.push_back(cur), cur = visit[cur];
}
path.push_back(A);
return path;
}
void Link(int A, int B) {
if (noSolution) return;
if (!join(A, B)) {
if (root != -1) {
if (find(root) != find(A)) {
noSolution = 1; return;
}
}
else {
root = A;
vcircle = findPath(A, B);
for (auto i : vcircle) inCircle[i] = 1;
}
}
deg[A]++, deg[B]++;
G[A].push_back(B), G[B].push_back(A);
if (deg[A] == 3) vnode.push_back(A);
if (deg[B] == 3) vnode.push_back(B);
if (vnode.size() == 3) {
noSolution = 1; return;
}
if (vnode.size() == 2) {
if (deg[vnode[0]] != 3 || deg[vnode[1]] != 3) {
noSolution = 1; return;
}
if (checkConnect) return;
checkConnect = 1;
bool found = 0;
for (auto v : G[vnode[0]]) {
found |= v == vnode[1];
}
if (!found) {
noSolution = 1; return;
}
}
}
int CountCritical() {
if (noSolution) return 0;
if (!vnode.size()) {
if (root != -1) return vcircle.size();
else return n;
}
if (vnode.size() == 1) {
if (root != -1 && !inCircle[vnode[0]]) {
noSolution = 1; return 0;
}
if (deg[vnode[0]] > 3) return 1;
if (root != -1) return 3;
return 4;
}
if (root != -1 && (!inCircle[vnode[0]] || !inCircle[vnode[1]])) {
noSolution = 1; return 0;
}
return 2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24060 KB |
Output is correct |
3 |
Correct |
31 ms |
24120 KB |
Output is correct |
4 |
Correct |
23 ms |
24120 KB |
Output is correct |
5 |
Correct |
24 ms |
24120 KB |
Output is correct |
6 |
Correct |
24 ms |
24368 KB |
Output is correct |
7 |
Correct |
22 ms |
24368 KB |
Output is correct |
8 |
Correct |
24 ms |
24368 KB |
Output is correct |
9 |
Correct |
24 ms |
24368 KB |
Output is correct |
10 |
Incorrect |
26 ms |
24368 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
44484 KB |
Output is correct |
2 |
Correct |
929 ms |
55356 KB |
Output is correct |
3 |
Correct |
306 ms |
55356 KB |
Output is correct |
4 |
Correct |
1217 ms |
68036 KB |
Output is correct |
5 |
Correct |
1171 ms |
68264 KB |
Output is correct |
6 |
Correct |
1307 ms |
69084 KB |
Output is correct |
7 |
Correct |
297 ms |
69084 KB |
Output is correct |
8 |
Correct |
1110 ms |
69084 KB |
Output is correct |
9 |
Incorrect |
1098 ms |
69084 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24060 KB |
Output is correct |
3 |
Correct |
31 ms |
24120 KB |
Output is correct |
4 |
Correct |
23 ms |
24120 KB |
Output is correct |
5 |
Correct |
24 ms |
24120 KB |
Output is correct |
6 |
Correct |
24 ms |
24368 KB |
Output is correct |
7 |
Correct |
22 ms |
24368 KB |
Output is correct |
8 |
Correct |
24 ms |
24368 KB |
Output is correct |
9 |
Correct |
24 ms |
24368 KB |
Output is correct |
10 |
Incorrect |
26 ms |
24368 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24060 KB |
Output is correct |
3 |
Correct |
31 ms |
24120 KB |
Output is correct |
4 |
Correct |
23 ms |
24120 KB |
Output is correct |
5 |
Correct |
24 ms |
24120 KB |
Output is correct |
6 |
Correct |
24 ms |
24368 KB |
Output is correct |
7 |
Correct |
22 ms |
24368 KB |
Output is correct |
8 |
Correct |
24 ms |
24368 KB |
Output is correct |
9 |
Correct |
24 ms |
24368 KB |
Output is correct |
10 |
Incorrect |
26 ms |
24368 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24060 KB |
Output is correct |
3 |
Correct |
31 ms |
24120 KB |
Output is correct |
4 |
Correct |
23 ms |
24120 KB |
Output is correct |
5 |
Correct |
24 ms |
24120 KB |
Output is correct |
6 |
Correct |
24 ms |
24368 KB |
Output is correct |
7 |
Correct |
22 ms |
24368 KB |
Output is correct |
8 |
Correct |
24 ms |
24368 KB |
Output is correct |
9 |
Correct |
24 ms |
24368 KB |
Output is correct |
10 |
Incorrect |
26 ms |
24368 KB |
Output isn't correct |