#include <bits/stdc++.h>
using namespace std;
int n, phase = 0;
vector<int> p, sz, cyc;
vector< vector<int> > g;
vector< pair<int, int> > edges;
class candidate {
private:
int u;
bool pos = true;
vector<int> p, deg;
int root(int x) {
if (p[x] == -1) return x;
return p[x] = root(p[x]);
}
public:
candidate(int _u) {
p.assign(n, -1);
deg.assign(n, 0);
u = _u;
}
void add_edge(int x, int y) {
if (x == u || y == u) return;
if (++deg[x] > 2) pos = false;
if (++deg[y] > 2) pos = false;
x = root(x); y = root(y);
if (x == y) pos = false;
else p[y] = x;
}
operator int() const {
return pos;
}
};
vector<candidate> candidates;
int root(int x) {
if (p[x] == -1) return x;
return p[x] = root(p[x]);
}
void connect(int x, int y) {
x = root(x); y = root(y);
if (x == y) cyc.push_back(x);
else {
p[y] = x; sz[x] += sz[y];
}
}
void Init(int N_) {
n = N_;
p.assign(n, -1);
sz.assign(n, 1);
g.resize(n);
}
void Link(int A, int B) {
if (phase == 0) {
g[A].push_back(B);
g[B].push_back(A);
edges.push_back({A, B});
connect(A, B);
if ((int) g[A].size() < (int) g[B].size()) swap(A, B);
if ((int) g[A].size() == 3) {
phase = 1;
candidates.emplace_back(A);
for (auto& x : g[A]) candidates.emplace_back(x);
for (auto& e : edges) for (auto& c : candidates) c.add_edge(e.first, e.second);
}
} else {
for (auto& c : candidates) c.add_edge(A, B);
}
}
int CountCritical() {
if (phase == 0) {
if (cyc.empty()) return n;
if ((int) cyc.size() > 1) return 0;
return sz[root(cyc[0])];
} else {
int ans = 0;
for (auto& c : candidates) ans += c;
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
748 KB |
Output is correct |
3 |
Correct |
2 ms |
748 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
3 ms |
748 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
876 KB |
Output is correct |
10 |
Correct |
3 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
424 ms |
37076 KB |
Output is correct |
2 |
Correct |
917 ms |
66656 KB |
Output is correct |
3 |
Correct |
1526 ms |
63516 KB |
Output is correct |
4 |
Correct |
1135 ms |
70728 KB |
Output is correct |
5 |
Correct |
1143 ms |
84296 KB |
Output is correct |
6 |
Correct |
1129 ms |
82396 KB |
Output is correct |
7 |
Correct |
1409 ms |
75920 KB |
Output is correct |
8 |
Correct |
1295 ms |
103252 KB |
Output is correct |
9 |
Correct |
1482 ms |
113284 KB |
Output is correct |
10 |
Correct |
780 ms |
81864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
748 KB |
Output is correct |
3 |
Correct |
2 ms |
748 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
3 ms |
748 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
876 KB |
Output is correct |
10 |
Correct |
3 ms |
876 KB |
Output is correct |
11 |
Correct |
3 ms |
876 KB |
Output is correct |
12 |
Correct |
8 ms |
1516 KB |
Output is correct |
13 |
Correct |
5 ms |
1260 KB |
Output is correct |
14 |
Correct |
3 ms |
1004 KB |
Output is correct |
15 |
Correct |
6 ms |
1644 KB |
Output is correct |
16 |
Correct |
5 ms |
1132 KB |
Output is correct |
17 |
Correct |
4 ms |
1132 KB |
Output is correct |
18 |
Correct |
5 ms |
1772 KB |
Output is correct |
19 |
Correct |
5 ms |
1260 KB |
Output is correct |
20 |
Correct |
6 ms |
1388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
748 KB |
Output is correct |
3 |
Correct |
2 ms |
748 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
3 ms |
748 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
876 KB |
Output is correct |
10 |
Correct |
3 ms |
876 KB |
Output is correct |
11 |
Correct |
3 ms |
876 KB |
Output is correct |
12 |
Correct |
8 ms |
1516 KB |
Output is correct |
13 |
Correct |
5 ms |
1260 KB |
Output is correct |
14 |
Correct |
3 ms |
1004 KB |
Output is correct |
15 |
Correct |
6 ms |
1644 KB |
Output is correct |
16 |
Correct |
5 ms |
1132 KB |
Output is correct |
17 |
Correct |
4 ms |
1132 KB |
Output is correct |
18 |
Correct |
5 ms |
1772 KB |
Output is correct |
19 |
Correct |
5 ms |
1260 KB |
Output is correct |
20 |
Correct |
6 ms |
1388 KB |
Output is correct |
21 |
Correct |
20 ms |
3560 KB |
Output is correct |
22 |
Correct |
32 ms |
5348 KB |
Output is correct |
23 |
Correct |
41 ms |
6756 KB |
Output is correct |
24 |
Correct |
45 ms |
7148 KB |
Output is correct |
25 |
Correct |
17 ms |
6892 KB |
Output is correct |
26 |
Correct |
42 ms |
7404 KB |
Output is correct |
27 |
Correct |
50 ms |
7412 KB |
Output is correct |
28 |
Correct |
40 ms |
7148 KB |
Output is correct |
29 |
Correct |
31 ms |
7532 KB |
Output is correct |
30 |
Correct |
72 ms |
8416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
748 KB |
Output is correct |
3 |
Correct |
2 ms |
748 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
3 ms |
748 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
876 KB |
Output is correct |
10 |
Correct |
3 ms |
876 KB |
Output is correct |
11 |
Correct |
424 ms |
37076 KB |
Output is correct |
12 |
Correct |
917 ms |
66656 KB |
Output is correct |
13 |
Correct |
1526 ms |
63516 KB |
Output is correct |
14 |
Correct |
1135 ms |
70728 KB |
Output is correct |
15 |
Correct |
1143 ms |
84296 KB |
Output is correct |
16 |
Correct |
1129 ms |
82396 KB |
Output is correct |
17 |
Correct |
1409 ms |
75920 KB |
Output is correct |
18 |
Correct |
1295 ms |
103252 KB |
Output is correct |
19 |
Correct |
1482 ms |
113284 KB |
Output is correct |
20 |
Correct |
780 ms |
81864 KB |
Output is correct |
21 |
Correct |
3 ms |
876 KB |
Output is correct |
22 |
Correct |
8 ms |
1516 KB |
Output is correct |
23 |
Correct |
5 ms |
1260 KB |
Output is correct |
24 |
Correct |
3 ms |
1004 KB |
Output is correct |
25 |
Correct |
6 ms |
1644 KB |
Output is correct |
26 |
Correct |
5 ms |
1132 KB |
Output is correct |
27 |
Correct |
4 ms |
1132 KB |
Output is correct |
28 |
Correct |
5 ms |
1772 KB |
Output is correct |
29 |
Correct |
5 ms |
1260 KB |
Output is correct |
30 |
Correct |
6 ms |
1388 KB |
Output is correct |
31 |
Correct |
20 ms |
3560 KB |
Output is correct |
32 |
Correct |
32 ms |
5348 KB |
Output is correct |
33 |
Correct |
41 ms |
6756 KB |
Output is correct |
34 |
Correct |
45 ms |
7148 KB |
Output is correct |
35 |
Correct |
17 ms |
6892 KB |
Output is correct |
36 |
Correct |
42 ms |
7404 KB |
Output is correct |
37 |
Correct |
50 ms |
7412 KB |
Output is correct |
38 |
Correct |
40 ms |
7148 KB |
Output is correct |
39 |
Correct |
31 ms |
7532 KB |
Output is correct |
40 |
Correct |
72 ms |
8416 KB |
Output is correct |
41 |
Correct |
229 ms |
29688 KB |
Output is correct |
42 |
Correct |
585 ms |
74944 KB |
Output is correct |
43 |
Correct |
287 ms |
63468 KB |
Output is correct |
44 |
Correct |
635 ms |
70892 KB |
Output is correct |
45 |
Correct |
913 ms |
73960 KB |
Output is correct |
46 |
Correct |
835 ms |
70508 KB |
Output is correct |
47 |
Correct |
981 ms |
71756 KB |
Output is correct |
48 |
Correct |
436 ms |
71704 KB |
Output is correct |
49 |
Correct |
697 ms |
73288 KB |
Output is correct |
50 |
Correct |
762 ms |
72520 KB |
Output is correct |
51 |
Correct |
302 ms |
54896 KB |
Output is correct |
52 |
Correct |
590 ms |
57580 KB |
Output is correct |
53 |
Correct |
410 ms |
70636 KB |
Output is correct |
54 |
Correct |
1042 ms |
84548 KB |
Output is correct |
55 |
Correct |
882 ms |
68104 KB |
Output is correct |