#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1000001;
vector<int> adj[N];
int U_i[N], V_i[N];
int small_case, cycle, gg, tot;
int deg[N], p[N], sz[N];
int n, ans;
class solve {
private:
int deg[N], p[N];
int fr(int i) {
return p[i] == i ? i : p[i] = fr(p[i]);
}
public:
int root, ans;
void Link(int A, int B) {
if (!ans) return;
if (A == root || B == root) return;
if (++deg[A] == 3 || ++deg[B] == 3) {
ans = 0;
return;
}
int pa = fr(A), pb = fr(B);
if (pa == pb) {
ans = 0;
return;
}
p[pb] = pa;
}
void init() {
ans = 1;
for (int i = 0;i < n;i++) p[i] = i;
for (int i = 0;i < tot;i++) {
Link(U_i[i], V_i[i]);
}
}
} U[4];
int fr(int i) {
return p[i] == i ? i : p[i] = fr(p[i]);
}
void Init(int N_) {
n = N_;
ans = n;
for (int i = 0;i < n;i++) p[i] = i, sz[i] = 1;
}
void Link(int A, int B) {
U_i[tot] = A, V_i[tot] = B, tot++;
if (gg) return;
if (small_case) {
for (int i = 0;i < 4;i++) U[i].Link(A, B);
return;
}
adj[A].push_back(B);
adj[B].push_back(A);
if (++deg[A] == 3) {
small_case = 1;
U[0].root = A;
int idx = 1;
for (auto& x : adj[A]) U[idx++].root = x;
}
if (++deg[B] == 3) {
small_case = 1;
U[0].root = B;
int idx = 1;
for (auto& x : adj[B]) U[idx++].root = x;
}
if (small_case) {
for (int i = 0;i < 4;i++) U[i].init();
return;
}
int pa = fr(A), pb = fr(B);
if (pa == pb) {
if (!cycle) ans = sz[pa], cycle = 1;
else gg = 1;
}
else sz[pa] += sz[pb], p[pb] = pa;
}
int CountCritical() {
if (gg) return 0;
if (!small_case) return ans;
return U[0].ans + U[1].ans + U[2].ans + U[3].ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
24356 KB |
Output is correct |
3 |
Correct |
11 ms |
24156 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
24156 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
10 ms |
24156 KB |
Output is correct |
8 |
Correct |
13 ms |
24408 KB |
Output is correct |
9 |
Correct |
12 ms |
24412 KB |
Output is correct |
10 |
Correct |
11 ms |
24408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
57168 KB |
Output is correct |
2 |
Correct |
269 ms |
89168 KB |
Output is correct |
3 |
Correct |
157 ms |
87448 KB |
Output is correct |
4 |
Correct |
584 ms |
87988 KB |
Output is correct |
5 |
Correct |
566 ms |
88144 KB |
Output is correct |
6 |
Correct |
585 ms |
86592 KB |
Output is correct |
7 |
Correct |
154 ms |
86608 KB |
Output is correct |
8 |
Correct |
486 ms |
110420 KB |
Output is correct |
9 |
Correct |
604 ms |
118332 KB |
Output is correct |
10 |
Correct |
381 ms |
85076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
24356 KB |
Output is correct |
3 |
Correct |
11 ms |
24156 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
24156 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
10 ms |
24156 KB |
Output is correct |
8 |
Correct |
13 ms |
24408 KB |
Output is correct |
9 |
Correct |
12 ms |
24412 KB |
Output is correct |
10 |
Correct |
11 ms |
24408 KB |
Output is correct |
11 |
Correct |
12 ms |
24408 KB |
Output is correct |
12 |
Correct |
12 ms |
24920 KB |
Output is correct |
13 |
Correct |
12 ms |
24668 KB |
Output is correct |
14 |
Correct |
10 ms |
24600 KB |
Output is correct |
15 |
Correct |
11 ms |
24668 KB |
Output is correct |
16 |
Correct |
15 ms |
24572 KB |
Output is correct |
17 |
Correct |
11 ms |
24668 KB |
Output is correct |
18 |
Correct |
12 ms |
24924 KB |
Output is correct |
19 |
Correct |
12 ms |
24436 KB |
Output is correct |
20 |
Correct |
12 ms |
24692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
24356 KB |
Output is correct |
3 |
Correct |
11 ms |
24156 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
24156 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
10 ms |
24156 KB |
Output is correct |
8 |
Correct |
13 ms |
24408 KB |
Output is correct |
9 |
Correct |
12 ms |
24412 KB |
Output is correct |
10 |
Correct |
11 ms |
24408 KB |
Output is correct |
11 |
Correct |
12 ms |
24408 KB |
Output is correct |
12 |
Correct |
12 ms |
24920 KB |
Output is correct |
13 |
Correct |
12 ms |
24668 KB |
Output is correct |
14 |
Correct |
10 ms |
24600 KB |
Output is correct |
15 |
Correct |
11 ms |
24668 KB |
Output is correct |
16 |
Correct |
15 ms |
24572 KB |
Output is correct |
17 |
Correct |
11 ms |
24668 KB |
Output is correct |
18 |
Correct |
12 ms |
24924 KB |
Output is correct |
19 |
Correct |
12 ms |
24436 KB |
Output is correct |
20 |
Correct |
12 ms |
24692 KB |
Output is correct |
21 |
Correct |
21 ms |
26200 KB |
Output is correct |
22 |
Correct |
26 ms |
27420 KB |
Output is correct |
23 |
Correct |
34 ms |
28324 KB |
Output is correct |
24 |
Correct |
24 ms |
27996 KB |
Output is correct |
25 |
Correct |
16 ms |
27484 KB |
Output is correct |
26 |
Correct |
25 ms |
29468 KB |
Output is correct |
27 |
Correct |
37 ms |
28760 KB |
Output is correct |
28 |
Correct |
23 ms |
29688 KB |
Output is correct |
29 |
Correct |
22 ms |
29276 KB |
Output is correct |
30 |
Correct |
38 ms |
29988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
24356 KB |
Output is correct |
3 |
Correct |
11 ms |
24156 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
24156 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
10 ms |
24156 KB |
Output is correct |
8 |
Correct |
13 ms |
24408 KB |
Output is correct |
9 |
Correct |
12 ms |
24412 KB |
Output is correct |
10 |
Correct |
11 ms |
24408 KB |
Output is correct |
11 |
Correct |
199 ms |
57168 KB |
Output is correct |
12 |
Correct |
269 ms |
89168 KB |
Output is correct |
13 |
Correct |
157 ms |
87448 KB |
Output is correct |
14 |
Correct |
584 ms |
87988 KB |
Output is correct |
15 |
Correct |
566 ms |
88144 KB |
Output is correct |
16 |
Correct |
585 ms |
86592 KB |
Output is correct |
17 |
Correct |
154 ms |
86608 KB |
Output is correct |
18 |
Correct |
486 ms |
110420 KB |
Output is correct |
19 |
Correct |
604 ms |
118332 KB |
Output is correct |
20 |
Correct |
381 ms |
85076 KB |
Output is correct |
21 |
Correct |
12 ms |
24408 KB |
Output is correct |
22 |
Correct |
12 ms |
24920 KB |
Output is correct |
23 |
Correct |
12 ms |
24668 KB |
Output is correct |
24 |
Correct |
10 ms |
24600 KB |
Output is correct |
25 |
Correct |
11 ms |
24668 KB |
Output is correct |
26 |
Correct |
15 ms |
24572 KB |
Output is correct |
27 |
Correct |
11 ms |
24668 KB |
Output is correct |
28 |
Correct |
12 ms |
24924 KB |
Output is correct |
29 |
Correct |
12 ms |
24436 KB |
Output is correct |
30 |
Correct |
12 ms |
24692 KB |
Output is correct |
31 |
Correct |
21 ms |
26200 KB |
Output is correct |
32 |
Correct |
26 ms |
27420 KB |
Output is correct |
33 |
Correct |
34 ms |
28324 KB |
Output is correct |
34 |
Correct |
24 ms |
27996 KB |
Output is correct |
35 |
Correct |
16 ms |
27484 KB |
Output is correct |
36 |
Correct |
25 ms |
29468 KB |
Output is correct |
37 |
Correct |
37 ms |
28760 KB |
Output is correct |
38 |
Correct |
23 ms |
29688 KB |
Output is correct |
39 |
Correct |
22 ms |
29276 KB |
Output is correct |
40 |
Correct |
38 ms |
29988 KB |
Output is correct |
41 |
Correct |
117 ms |
43344 KB |
Output is correct |
42 |
Correct |
259 ms |
82772 KB |
Output is correct |
43 |
Correct |
118 ms |
56656 KB |
Output is correct |
44 |
Correct |
152 ms |
82952 KB |
Output is correct |
45 |
Correct |
198 ms |
82488 KB |
Output is correct |
46 |
Correct |
338 ms |
77396 KB |
Output is correct |
47 |
Correct |
523 ms |
78928 KB |
Output is correct |
48 |
Correct |
144 ms |
77992 KB |
Output is correct |
49 |
Correct |
374 ms |
77120 KB |
Output is correct |
50 |
Correct |
377 ms |
76540 KB |
Output is correct |
51 |
Correct |
123 ms |
62544 KB |
Output is correct |
52 |
Correct |
145 ms |
72016 KB |
Output is correct |
53 |
Correct |
127 ms |
77136 KB |
Output is correct |
54 |
Correct |
367 ms |
95280 KB |
Output is correct |
55 |
Correct |
201 ms |
81368 KB |
Output is correct |