#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], cycle;
bool bad[5];
vector<int> g[maxn][5], 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][0].push_back(B);
g[B][0].push_back(A);
if (g[A][0].size() == 3){
bad[0] = true;
ver.push_back(A);
for (auto x: g[A][0])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][0]){
if (u < j || u == ver[i-1]) continue;
g[j][i].push_back(u);
g[u][i].push_back(j);
if (max(g[j][i].size(), g[u][i].size()) > 2 || !merge(i, j, u)) bad[i] = true;
}
}
}
}
else if (g[B][0].size() == 3){
bad[0] = true;
ver.push_back(B);
for (auto x: g[B][0])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][0]){
if (u < j || u == ver[i-1]) continue;
g[j][i].push_back(u);
g[u][i].push_back(j);
if (max(g[j][i].size(), g[u][i].size()) > 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]){
g[A][i].push_back(B);
g[B][i].push_back(A);
if (max(g[A][i].size(), g[B][i].size()) > 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++){
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
137164 KB |
Output is correct |
2 |
Correct |
64 ms |
137852 KB |
Output is correct |
3 |
Correct |
63 ms |
137932 KB |
Output is correct |
4 |
Correct |
65 ms |
137396 KB |
Output is correct |
5 |
Correct |
61 ms |
137380 KB |
Output is correct |
6 |
Correct |
62 ms |
137400 KB |
Output is correct |
7 |
Correct |
61 ms |
137392 KB |
Output is correct |
8 |
Correct |
61 ms |
137416 KB |
Output is correct |
9 |
Correct |
64 ms |
137920 KB |
Output is correct |
10 |
Correct |
63 ms |
138048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
295 ms |
153572 KB |
Output is correct |
2 |
Correct |
1719 ms |
251224 KB |
Output is correct |
3 |
Correct |
1404 ms |
246520 KB |
Output is correct |
4 |
Correct |
732 ms |
168480 KB |
Output is correct |
5 |
Correct |
754 ms |
168564 KB |
Output is correct |
6 |
Correct |
736 ms |
167540 KB |
Output is correct |
7 |
Correct |
1348 ms |
244700 KB |
Output is correct |
8 |
Runtime error |
1287 ms |
262144 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
137164 KB |
Output is correct |
2 |
Correct |
64 ms |
137852 KB |
Output is correct |
3 |
Correct |
63 ms |
137932 KB |
Output is correct |
4 |
Correct |
65 ms |
137396 KB |
Output is correct |
5 |
Correct |
61 ms |
137380 KB |
Output is correct |
6 |
Correct |
62 ms |
137400 KB |
Output is correct |
7 |
Correct |
61 ms |
137392 KB |
Output is correct |
8 |
Correct |
61 ms |
137416 KB |
Output is correct |
9 |
Correct |
64 ms |
137920 KB |
Output is correct |
10 |
Correct |
63 ms |
138048 KB |
Output is correct |
11 |
Correct |
64 ms |
138016 KB |
Output is correct |
12 |
Correct |
68 ms |
138828 KB |
Output is correct |
13 |
Correct |
68 ms |
138672 KB |
Output is correct |
14 |
Correct |
65 ms |
137996 KB |
Output is correct |
15 |
Correct |
64 ms |
137804 KB |
Output is correct |
16 |
Correct |
63 ms |
137532 KB |
Output is correct |
17 |
Correct |
70 ms |
138496 KB |
Output is correct |
18 |
Correct |
68 ms |
138852 KB |
Output is correct |
19 |
Correct |
63 ms |
137584 KB |
Output is correct |
20 |
Correct |
69 ms |
138824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
137164 KB |
Output is correct |
2 |
Correct |
64 ms |
137852 KB |
Output is correct |
3 |
Correct |
63 ms |
137932 KB |
Output is correct |
4 |
Correct |
65 ms |
137396 KB |
Output is correct |
5 |
Correct |
61 ms |
137380 KB |
Output is correct |
6 |
Correct |
62 ms |
137400 KB |
Output is correct |
7 |
Correct |
61 ms |
137392 KB |
Output is correct |
8 |
Correct |
61 ms |
137416 KB |
Output is correct |
9 |
Correct |
64 ms |
137920 KB |
Output is correct |
10 |
Correct |
63 ms |
138048 KB |
Output is correct |
11 |
Correct |
64 ms |
138016 KB |
Output is correct |
12 |
Correct |
68 ms |
138828 KB |
Output is correct |
13 |
Correct |
68 ms |
138672 KB |
Output is correct |
14 |
Correct |
65 ms |
137996 KB |
Output is correct |
15 |
Correct |
64 ms |
137804 KB |
Output is correct |
16 |
Correct |
63 ms |
137532 KB |
Output is correct |
17 |
Correct |
70 ms |
138496 KB |
Output is correct |
18 |
Correct |
68 ms |
138852 KB |
Output is correct |
19 |
Correct |
63 ms |
137584 KB |
Output is correct |
20 |
Correct |
69 ms |
138824 KB |
Output is correct |
21 |
Correct |
78 ms |
138356 KB |
Output is correct |
22 |
Correct |
95 ms |
138812 KB |
Output is correct |
23 |
Correct |
88 ms |
139348 KB |
Output is correct |
24 |
Correct |
103 ms |
143052 KB |
Output is correct |
25 |
Correct |
72 ms |
137940 KB |
Output is correct |
26 |
Correct |
113 ms |
145460 KB |
Output is correct |
27 |
Correct |
92 ms |
139672 KB |
Output is correct |
28 |
Correct |
118 ms |
148372 KB |
Output is correct |
29 |
Correct |
98 ms |
143252 KB |
Output is correct |
30 |
Correct |
101 ms |
140368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
137164 KB |
Output is correct |
2 |
Correct |
64 ms |
137852 KB |
Output is correct |
3 |
Correct |
63 ms |
137932 KB |
Output is correct |
4 |
Correct |
65 ms |
137396 KB |
Output is correct |
5 |
Correct |
61 ms |
137380 KB |
Output is correct |
6 |
Correct |
62 ms |
137400 KB |
Output is correct |
7 |
Correct |
61 ms |
137392 KB |
Output is correct |
8 |
Correct |
61 ms |
137416 KB |
Output is correct |
9 |
Correct |
64 ms |
137920 KB |
Output is correct |
10 |
Correct |
63 ms |
138048 KB |
Output is correct |
11 |
Correct |
295 ms |
153572 KB |
Output is correct |
12 |
Correct |
1719 ms |
251224 KB |
Output is correct |
13 |
Correct |
1404 ms |
246520 KB |
Output is correct |
14 |
Correct |
732 ms |
168480 KB |
Output is correct |
15 |
Correct |
754 ms |
168564 KB |
Output is correct |
16 |
Correct |
736 ms |
167540 KB |
Output is correct |
17 |
Correct |
1348 ms |
244700 KB |
Output is correct |
18 |
Runtime error |
1287 ms |
262144 KB |
Execution killed with signal 9 |
19 |
Halted |
0 ms |
0 KB |
- |