#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;
void debug_out(){cerr<<endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cout << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 1e6 + 10;
int n, par[5][maxn], d[5][maxn], cycle;
bool bad[5];
vector<int> g[maxn], ver;
int getpar(int idx, int v){
return (par[idx][v] < 0? v: par[idx][v] = getpar(idx, par[idx][v]));
}
bool merge(int idx, int x, int y){
int u = getpar(idx, x);
int v = getpar(idx, y);
if (u == v) return false;
par[idx][u] += par[idx][v];
par[idx][v] = u;
return true;
}
void Init(int N_) {
memset(par, -1, sizeof par);
n = N_;
}
void Link(int A, int B) {
if (!bad[0]){
g[A].push_back(B);
g[B].push_back(A);
if (g[A].size() == 3){
bad[0] = true;
ver.push_back(A);
for (auto x: g[A])ver.push_back(x);
for (int i = 1; i <= ver.size(); i++){
for (int j = 0; j < n; j++){
if (j == ver[i-1]) continue;
for (auto u: g[j]){
if (u < j || u == ver[i-1]) continue;
d[i][j]++;
d[i][u]++;
if (max(d[i][j], d[i][u]) > 2 || !merge(i, j, u)) bad[i] = true;
}
}
}
}
else if (g[B].size() == 3){
bad[0] = true;
ver.push_back(B);
for (auto x: g[B])ver.push_back(x);
for (int i = 1; i <= ver.size(); i++){
for (int j = 0; j < n; j++){
if (j == ver[i-1]) continue;
for (auto u: g[j]){
if (u < j || u == ver[i-1]) continue;
d[i][j]++;
d[i][u]++;
if (max(d[i][j], d[i][u]) > 2 || !merge(i, j, u)) bad[i] = true;
}
}
}
}
if (!merge(0, A, B)){
if (cycle != 0) bad[0] = true;
cycle = -par[0][getpar(0, A)];
}
return;
}
for (int i = 1; i <= ver.size(); i++){
if (A != ver[i-1] && B != ver[i-1]){
d[i][A]++;
d[i][B]++;
if (max(d[i][A], d[i][B]) > 2 || !merge(i, A, B)) bad[i] = true;
}
}
}
int CountCritical() {
if (!bad[0]){
if (cycle == 0) return n;
return cycle;
}
int ans = 0;
for (int i = 1; i <= ver.size(); i++){
ans += (!bad[i]);
}
return ans;
}
Compilation message
rings.cpp: In function 'void Link(int, int)':
rings.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 1; i <= ver.size(); i++){
| ~~^~~~~~~~~~~~~
rings.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i = 1; i <= ver.size(); i++){
| ~~^~~~~~~~~~~~~
rings.cpp:90:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for (int i = 1; i <= ver.size(); i++){
| ~~^~~~~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:105:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for (int i = 1; i <= ver.size(); i++){
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
43368 KB |
Output is correct |
2 |
Correct |
20 ms |
43476 KB |
Output is correct |
3 |
Correct |
20 ms |
43476 KB |
Output is correct |
4 |
Correct |
19 ms |
43356 KB |
Output is correct |
5 |
Correct |
20 ms |
43456 KB |
Output is correct |
6 |
Correct |
21 ms |
43488 KB |
Output is correct |
7 |
Correct |
19 ms |
43392 KB |
Output is correct |
8 |
Correct |
21 ms |
43476 KB |
Output is correct |
9 |
Correct |
20 ms |
43604 KB |
Output is correct |
10 |
Correct |
22 ms |
43536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
243 ms |
59656 KB |
Output is correct |
2 |
Correct |
595 ms |
69836 KB |
Output is correct |
3 |
Correct |
492 ms |
59440 KB |
Output is correct |
4 |
Correct |
669 ms |
74648 KB |
Output is correct |
5 |
Correct |
667 ms |
74644 KB |
Output is correct |
6 |
Correct |
637 ms |
73592 KB |
Output is correct |
7 |
Correct |
473 ms |
59572 KB |
Output is correct |
8 |
Correct |
851 ms |
84364 KB |
Output is correct |
9 |
Correct |
1020 ms |
89328 KB |
Output is correct |
10 |
Correct |
407 ms |
72892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
43368 KB |
Output is correct |
2 |
Correct |
20 ms |
43476 KB |
Output is correct |
3 |
Correct |
20 ms |
43476 KB |
Output is correct |
4 |
Correct |
19 ms |
43356 KB |
Output is correct |
5 |
Correct |
20 ms |
43456 KB |
Output is correct |
6 |
Correct |
21 ms |
43488 KB |
Output is correct |
7 |
Correct |
19 ms |
43392 KB |
Output is correct |
8 |
Correct |
21 ms |
43476 KB |
Output is correct |
9 |
Correct |
20 ms |
43604 KB |
Output is correct |
10 |
Correct |
22 ms |
43536 KB |
Output is correct |
11 |
Correct |
20 ms |
43592 KB |
Output is correct |
12 |
Correct |
22 ms |
43860 KB |
Output is correct |
13 |
Correct |
21 ms |
43788 KB |
Output is correct |
14 |
Correct |
20 ms |
43492 KB |
Output is correct |
15 |
Correct |
21 ms |
43732 KB |
Output is correct |
16 |
Correct |
22 ms |
43604 KB |
Output is correct |
17 |
Correct |
21 ms |
43604 KB |
Output is correct |
18 |
Correct |
22 ms |
43732 KB |
Output is correct |
19 |
Correct |
22 ms |
43676 KB |
Output is correct |
20 |
Correct |
23 ms |
43732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
43368 KB |
Output is correct |
2 |
Correct |
20 ms |
43476 KB |
Output is correct |
3 |
Correct |
20 ms |
43476 KB |
Output is correct |
4 |
Correct |
19 ms |
43356 KB |
Output is correct |
5 |
Correct |
20 ms |
43456 KB |
Output is correct |
6 |
Correct |
21 ms |
43488 KB |
Output is correct |
7 |
Correct |
19 ms |
43392 KB |
Output is correct |
8 |
Correct |
21 ms |
43476 KB |
Output is correct |
9 |
Correct |
20 ms |
43604 KB |
Output is correct |
10 |
Correct |
22 ms |
43536 KB |
Output is correct |
11 |
Correct |
20 ms |
43592 KB |
Output is correct |
12 |
Correct |
22 ms |
43860 KB |
Output is correct |
13 |
Correct |
21 ms |
43788 KB |
Output is correct |
14 |
Correct |
20 ms |
43492 KB |
Output is correct |
15 |
Correct |
21 ms |
43732 KB |
Output is correct |
16 |
Correct |
22 ms |
43604 KB |
Output is correct |
17 |
Correct |
21 ms |
43604 KB |
Output is correct |
18 |
Correct |
22 ms |
43732 KB |
Output is correct |
19 |
Correct |
22 ms |
43676 KB |
Output is correct |
20 |
Correct |
23 ms |
43732 KB |
Output is correct |
21 |
Correct |
32 ms |
44372 KB |
Output is correct |
22 |
Correct |
38 ms |
44960 KB |
Output is correct |
23 |
Correct |
43 ms |
45468 KB |
Output is correct |
24 |
Correct |
47 ms |
45020 KB |
Output is correct |
25 |
Correct |
28 ms |
45012 KB |
Output is correct |
26 |
Correct |
39 ms |
45076 KB |
Output is correct |
27 |
Correct |
43 ms |
45672 KB |
Output is correct |
28 |
Correct |
38 ms |
44884 KB |
Output is correct |
29 |
Correct |
45 ms |
45336 KB |
Output is correct |
30 |
Correct |
49 ms |
46492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
43368 KB |
Output is correct |
2 |
Correct |
20 ms |
43476 KB |
Output is correct |
3 |
Correct |
20 ms |
43476 KB |
Output is correct |
4 |
Correct |
19 ms |
43356 KB |
Output is correct |
5 |
Correct |
20 ms |
43456 KB |
Output is correct |
6 |
Correct |
21 ms |
43488 KB |
Output is correct |
7 |
Correct |
19 ms |
43392 KB |
Output is correct |
8 |
Correct |
21 ms |
43476 KB |
Output is correct |
9 |
Correct |
20 ms |
43604 KB |
Output is correct |
10 |
Correct |
22 ms |
43536 KB |
Output is correct |
11 |
Correct |
243 ms |
59656 KB |
Output is correct |
12 |
Correct |
595 ms |
69836 KB |
Output is correct |
13 |
Correct |
492 ms |
59440 KB |
Output is correct |
14 |
Correct |
669 ms |
74648 KB |
Output is correct |
15 |
Correct |
667 ms |
74644 KB |
Output is correct |
16 |
Correct |
637 ms |
73592 KB |
Output is correct |
17 |
Correct |
473 ms |
59572 KB |
Output is correct |
18 |
Correct |
851 ms |
84364 KB |
Output is correct |
19 |
Correct |
1020 ms |
89328 KB |
Output is correct |
20 |
Correct |
407 ms |
72892 KB |
Output is correct |
21 |
Correct |
20 ms |
43592 KB |
Output is correct |
22 |
Correct |
22 ms |
43860 KB |
Output is correct |
23 |
Correct |
21 ms |
43788 KB |
Output is correct |
24 |
Correct |
20 ms |
43492 KB |
Output is correct |
25 |
Correct |
21 ms |
43732 KB |
Output is correct |
26 |
Correct |
22 ms |
43604 KB |
Output is correct |
27 |
Correct |
21 ms |
43604 KB |
Output is correct |
28 |
Correct |
22 ms |
43732 KB |
Output is correct |
29 |
Correct |
22 ms |
43676 KB |
Output is correct |
30 |
Correct |
23 ms |
43732 KB |
Output is correct |
31 |
Correct |
32 ms |
44372 KB |
Output is correct |
32 |
Correct |
38 ms |
44960 KB |
Output is correct |
33 |
Correct |
43 ms |
45468 KB |
Output is correct |
34 |
Correct |
47 ms |
45020 KB |
Output is correct |
35 |
Correct |
28 ms |
45012 KB |
Output is correct |
36 |
Correct |
39 ms |
45076 KB |
Output is correct |
37 |
Correct |
43 ms |
45672 KB |
Output is correct |
38 |
Correct |
38 ms |
44884 KB |
Output is correct |
39 |
Correct |
45 ms |
45336 KB |
Output is correct |
40 |
Correct |
49 ms |
46492 KB |
Output is correct |
41 |
Correct |
144 ms |
51944 KB |
Output is correct |
42 |
Correct |
394 ms |
69012 KB |
Output is correct |
43 |
Correct |
194 ms |
59556 KB |
Output is correct |
44 |
Correct |
390 ms |
58228 KB |
Output is correct |
45 |
Correct |
398 ms |
61136 KB |
Output is correct |
46 |
Correct |
370 ms |
69588 KB |
Output is correct |
47 |
Correct |
554 ms |
70560 KB |
Output is correct |
48 |
Correct |
316 ms |
61068 KB |
Output is correct |
49 |
Correct |
439 ms |
69068 KB |
Output is correct |
50 |
Correct |
435 ms |
68760 KB |
Output is correct |
51 |
Correct |
203 ms |
57228 KB |
Output is correct |
52 |
Correct |
337 ms |
55608 KB |
Output is correct |
53 |
Correct |
306 ms |
60308 KB |
Output is correct |
54 |
Correct |
677 ms |
75420 KB |
Output is correct |
55 |
Correct |
516 ms |
57684 KB |
Output is correct |