#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define pii pair <int,int>
using namespace std;
const int N = 1e6 + 5;
vector <int> cycles,v[N];
vector <pii> edges;
int deg[N],n,nodes,p[N];
bool crit;
int critical[7],m,fail[7],degree[7][N];
int pp[7][N],sz[N];
void Init(int N_) {
crit=0;
n = N_;
for (int i = 0; i < n; i++)
p[i] = i,sz[i] = 1;
}
int P(int x){
if(x==p[x]) return x;
return p[x]=P(p[x]);
}
void dsu(int x,int y){
int px=P(x),py=P(y);
if (px == py){
cycles.pb(sz[px]);
return;
}
p[py] = px;
sz[px] += sz[py];
sz[py] = 0;
}
int PP(int i,int x){
if(pp[i][x] == x) return x;
return pp[i][x] = PP(i,pp[i][x]);
}
void dsuu(int i,int x,int y){
int px=PP(i,x),py=PP(i,y);
if (px == py){
fail[i] = 1;
return;
}
pp[i][py] = px;
}
void addedge(int i,int x,int y){
if (fail[i]) return;
if (x == critical[i] || y == critical[i]) return;
degree[i][x]++;
degree[i][y]++;
if (degree[i][x] > 2 || degree[i][y] > 2) {
fail[i] = 1;
return;
}
dsuu(i,x,y);
}
void Link(int A, int B) {
bool old = crit;
deg[A]++;
deg[B]++;
v[A].pb(B); v[B].pb(A);
edges.pb({A,B});
if (!crit){
if (deg[A] >= 3){
crit = 1;
if (deg[A] >= 4){
m = 1;
critical[1] = A;
} else{
m = 4;
critical[1] = A;
critical[2] = v[A][0];
critical[3] = v[A][1];
critical[4] = v[A][2];
}
}
}
if (!crit){
if (deg[B] >= 3){
crit = 1;
if (deg[B] >= 4){
m = 1;
critical[1] = B;
} else{
m = 4;
critical[1] = B;
critical[2] = v[B][0];
critical[3] = v[B][1];
critical[4] = v[B][2];
}
}
}
if (old){
for (int i = 1; i <= m; i++){
addedge(i,A,B);
}
}else if (!old && crit){
for (int i = 1; i <= m; i++){
fail[i] = 0;
for (int j = 0; j < n; j++){
pp[i][j] = j;
}
for (auto [x,y]: edges){
addedge(i,x,y);
}
}
}
if (crit) return;
dsu(A,B);
}
int CountCritical() {
if (crit){
int ans=0;
for (int i = 1; i <= m; i++){
ans += (!fail[i]);
}
return ans;
}
int ans = 0;
if (!cycles.size()) ans = n;
else if ((int)cycles.size() == 1) ans = cycles[0];
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
24152 KB |
Output is correct |
2 |
Correct |
14 ms |
24412 KB |
Output is correct |
3 |
Correct |
13 ms |
24364 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
24156 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
11 ms |
24156 KB |
Output is correct |
8 |
Correct |
14 ms |
24156 KB |
Output is correct |
9 |
Correct |
13 ms |
24408 KB |
Output is correct |
10 |
Correct |
14 ms |
24412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
57256 KB |
Output is correct |
2 |
Correct |
512 ms |
100164 KB |
Output is correct |
3 |
Correct |
497 ms |
114092 KB |
Output is correct |
4 |
Correct |
593 ms |
87976 KB |
Output is correct |
5 |
Correct |
611 ms |
88060 KB |
Output is correct |
6 |
Correct |
605 ms |
86364 KB |
Output is correct |
7 |
Correct |
425 ms |
112700 KB |
Output is correct |
8 |
Correct |
771 ms |
113320 KB |
Output is correct |
9 |
Correct |
696 ms |
119276 KB |
Output is correct |
10 |
Correct |
430 ms |
85672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
24152 KB |
Output is correct |
2 |
Correct |
14 ms |
24412 KB |
Output is correct |
3 |
Correct |
13 ms |
24364 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
24156 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
11 ms |
24156 KB |
Output is correct |
8 |
Correct |
14 ms |
24156 KB |
Output is correct |
9 |
Correct |
13 ms |
24408 KB |
Output is correct |
10 |
Correct |
14 ms |
24412 KB |
Output is correct |
11 |
Correct |
12 ms |
24412 KB |
Output is correct |
12 |
Correct |
14 ms |
24788 KB |
Output is correct |
13 |
Correct |
13 ms |
24924 KB |
Output is correct |
14 |
Correct |
13 ms |
24668 KB |
Output is correct |
15 |
Correct |
12 ms |
24920 KB |
Output is correct |
16 |
Correct |
12 ms |
24536 KB |
Output is correct |
17 |
Correct |
12 ms |
24912 KB |
Output is correct |
18 |
Correct |
13 ms |
25312 KB |
Output is correct |
19 |
Correct |
13 ms |
24668 KB |
Output is correct |
20 |
Correct |
14 ms |
25040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
24152 KB |
Output is correct |
2 |
Correct |
14 ms |
24412 KB |
Output is correct |
3 |
Correct |
13 ms |
24364 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
24156 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
11 ms |
24156 KB |
Output is correct |
8 |
Correct |
14 ms |
24156 KB |
Output is correct |
9 |
Correct |
13 ms |
24408 KB |
Output is correct |
10 |
Correct |
14 ms |
24412 KB |
Output is correct |
11 |
Correct |
12 ms |
24412 KB |
Output is correct |
12 |
Correct |
14 ms |
24788 KB |
Output is correct |
13 |
Correct |
13 ms |
24924 KB |
Output is correct |
14 |
Correct |
13 ms |
24668 KB |
Output is correct |
15 |
Correct |
12 ms |
24920 KB |
Output is correct |
16 |
Correct |
12 ms |
24536 KB |
Output is correct |
17 |
Correct |
12 ms |
24912 KB |
Output is correct |
18 |
Correct |
13 ms |
25312 KB |
Output is correct |
19 |
Correct |
13 ms |
24668 KB |
Output is correct |
20 |
Correct |
14 ms |
25040 KB |
Output is correct |
21 |
Correct |
20 ms |
26068 KB |
Output is correct |
22 |
Correct |
25 ms |
27340 KB |
Output is correct |
23 |
Correct |
31 ms |
28360 KB |
Output is correct |
24 |
Correct |
33 ms |
29644 KB |
Output is correct |
25 |
Correct |
17 ms |
27996 KB |
Output is correct |
26 |
Correct |
36 ms |
31444 KB |
Output is correct |
27 |
Correct |
41 ms |
29128 KB |
Output is correct |
28 |
Correct |
37 ms |
32204 KB |
Output is correct |
29 |
Correct |
31 ms |
30680 KB |
Output is correct |
30 |
Correct |
52 ms |
29892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
24152 KB |
Output is correct |
2 |
Correct |
14 ms |
24412 KB |
Output is correct |
3 |
Correct |
13 ms |
24364 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
24156 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
11 ms |
24156 KB |
Output is correct |
8 |
Correct |
14 ms |
24156 KB |
Output is correct |
9 |
Correct |
13 ms |
24408 KB |
Output is correct |
10 |
Correct |
14 ms |
24412 KB |
Output is correct |
11 |
Correct |
219 ms |
57256 KB |
Output is correct |
12 |
Correct |
512 ms |
100164 KB |
Output is correct |
13 |
Correct |
497 ms |
114092 KB |
Output is correct |
14 |
Correct |
593 ms |
87976 KB |
Output is correct |
15 |
Correct |
611 ms |
88060 KB |
Output is correct |
16 |
Correct |
605 ms |
86364 KB |
Output is correct |
17 |
Correct |
425 ms |
112700 KB |
Output is correct |
18 |
Correct |
771 ms |
113320 KB |
Output is correct |
19 |
Correct |
696 ms |
119276 KB |
Output is correct |
20 |
Correct |
430 ms |
85672 KB |
Output is correct |
21 |
Correct |
12 ms |
24412 KB |
Output is correct |
22 |
Correct |
14 ms |
24788 KB |
Output is correct |
23 |
Correct |
13 ms |
24924 KB |
Output is correct |
24 |
Correct |
13 ms |
24668 KB |
Output is correct |
25 |
Correct |
12 ms |
24920 KB |
Output is correct |
26 |
Correct |
12 ms |
24536 KB |
Output is correct |
27 |
Correct |
12 ms |
24912 KB |
Output is correct |
28 |
Correct |
13 ms |
25312 KB |
Output is correct |
29 |
Correct |
13 ms |
24668 KB |
Output is correct |
30 |
Correct |
14 ms |
25040 KB |
Output is correct |
31 |
Correct |
20 ms |
26068 KB |
Output is correct |
32 |
Correct |
25 ms |
27340 KB |
Output is correct |
33 |
Correct |
31 ms |
28360 KB |
Output is correct |
34 |
Correct |
33 ms |
29644 KB |
Output is correct |
35 |
Correct |
17 ms |
27996 KB |
Output is correct |
36 |
Correct |
36 ms |
31444 KB |
Output is correct |
37 |
Correct |
41 ms |
29128 KB |
Output is correct |
38 |
Correct |
37 ms |
32204 KB |
Output is correct |
39 |
Correct |
31 ms |
30680 KB |
Output is correct |
40 |
Correct |
52 ms |
29892 KB |
Output is correct |
41 |
Correct |
128 ms |
43712 KB |
Output is correct |
42 |
Correct |
311 ms |
86452 KB |
Output is correct |
43 |
Correct |
157 ms |
61644 KB |
Output is correct |
44 |
Correct |
378 ms |
110504 KB |
Output is correct |
45 |
Correct |
398 ms |
102328 KB |
Output is correct |
46 |
Correct |
530 ms |
77996 KB |
Output is correct |
47 |
Correct |
537 ms |
79024 KB |
Output is correct |
48 |
Correct |
266 ms |
92340 KB |
Output is correct |
49 |
Correct |
436 ms |
76968 KB |
Output is correct |
50 |
Correct |
438 ms |
76552 KB |
Output is correct |
51 |
Correct |
147 ms |
66876 KB |
Output is correct |
52 |
Correct |
316 ms |
94376 KB |
Output is correct |
53 |
Correct |
236 ms |
92744 KB |
Output is correct |
54 |
Correct |
554 ms |
101800 KB |
Output is correct |
55 |
Correct |
535 ms |
108460 KB |
Output is correct |