#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define X first
#define Y second
const int MAXN = 1e6 + 10;
int n , flag , invalid[5] , cycle[5] , root[5] , sz[5][MAXN] , par[5][MAXN] , deg[5][MAXN];
vector<int> adj[MAXN];
vector<pii> E;
void Init(int N_) {
n = N_;
for(int i = 0 ; i < 5 ; i++){
fill(par[i] , par[i] + MAXN , -1);
fill(sz[i] , sz[i] + MAXN , 1);
root[i] = -1;
}
root[0] = 0;
}
int Find(int ind , int v){
return (par[ind][v] == -1 ? v : par[ind][v] = Find(ind , par[ind][v]));
}
void Union(int ind , int v , int u){
v = Find(ind , v); u = Find(ind , u);
if(v == u) return;
if(sz[ind][v] < sz[ind][u]) swap(v , u);
par[ind][u] = v;
sz[ind][v] += sz[ind][u];
}
void add(int ind , int v , int u){
if(root[ind] == -1) return;
if(v == root[ind] || u == root[ind]) return;
deg[ind][v]++; deg[ind][u]++;
if(deg[ind][v] >= 3 || deg[ind][u] >= 3) invalid[ind] = 1;
if(Find(ind , v) == Find(ind , u)){
if(cycle[ind] != 0) cycle[ind] = -1;
else cycle[ind] = sz[ind][Find(ind , v)];
}
else Union(ind , v , u);
}
void Link(int A, int B) {
A++; B++;
E.push_back({A , B});
adj[A].push_back(B);
adj[B].push_back(A);
for(int i = 0 ; i < 5 ; i++) add(i , A , B);
if(flag) return;
if(deg[0][A] < deg[0][B]) swap(A , B);
if(deg[0][A] >= 3){
flag = 1;
root[1] = A; root[2] = adj[A][0];
root[3] = adj[A][1]; root[4] = adj[A][2];
for(pii i : E){
for(int j = 1 ; j < 5 ; j++) add(j , i.X , i.Y);
}
}
}
int CountCritical() {
if(invalid[0] == 0){
if(cycle[0] == 0) return n;
if(cycle[0] > 0) return cycle[0];
}
int ans = 0;
for(int i = 0 ; i < 5 ; i++){
if(root[i] != -1 && invalid[i] == 0 && cycle[i] == 0) ans++;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
62956 KB |
Output is correct |
2 |
Correct |
41 ms |
63212 KB |
Output is correct |
3 |
Correct |
41 ms |
63340 KB |
Output is correct |
4 |
Correct |
38 ms |
62976 KB |
Output is correct |
5 |
Correct |
40 ms |
63084 KB |
Output is correct |
6 |
Correct |
40 ms |
63340 KB |
Output is correct |
7 |
Correct |
39 ms |
63084 KB |
Output is correct |
8 |
Correct |
44 ms |
63212 KB |
Output is correct |
9 |
Correct |
41 ms |
63340 KB |
Output is correct |
10 |
Correct |
41 ms |
63348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
460 ms |
85332 KB |
Output is correct |
2 |
Correct |
1756 ms |
110060 KB |
Output is correct |
3 |
Correct |
2023 ms |
117424 KB |
Output is correct |
4 |
Correct |
1143 ms |
106312 KB |
Output is correct |
5 |
Correct |
1171 ms |
119572 KB |
Output is correct |
6 |
Correct |
1120 ms |
117972 KB |
Output is correct |
7 |
Correct |
1929 ms |
128596 KB |
Output is correct |
8 |
Correct |
1989 ms |
130460 KB |
Output is correct |
9 |
Correct |
2154 ms |
135056 KB |
Output is correct |
10 |
Correct |
766 ms |
116688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
62956 KB |
Output is correct |
2 |
Correct |
41 ms |
63212 KB |
Output is correct |
3 |
Correct |
41 ms |
63340 KB |
Output is correct |
4 |
Correct |
38 ms |
62976 KB |
Output is correct |
5 |
Correct |
40 ms |
63084 KB |
Output is correct |
6 |
Correct |
40 ms |
63340 KB |
Output is correct |
7 |
Correct |
39 ms |
63084 KB |
Output is correct |
8 |
Correct |
44 ms |
63212 KB |
Output is correct |
9 |
Correct |
41 ms |
63340 KB |
Output is correct |
10 |
Correct |
41 ms |
63348 KB |
Output is correct |
11 |
Correct |
42 ms |
63340 KB |
Output is correct |
12 |
Correct |
46 ms |
63724 KB |
Output is correct |
13 |
Correct |
46 ms |
63724 KB |
Output is correct |
14 |
Correct |
46 ms |
63468 KB |
Output is correct |
15 |
Correct |
44 ms |
63724 KB |
Output is correct |
16 |
Correct |
49 ms |
63596 KB |
Output is correct |
17 |
Correct |
46 ms |
63724 KB |
Output is correct |
18 |
Correct |
49 ms |
64000 KB |
Output is correct |
19 |
Correct |
45 ms |
63596 KB |
Output is correct |
20 |
Correct |
46 ms |
63852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
62956 KB |
Output is correct |
2 |
Correct |
41 ms |
63212 KB |
Output is correct |
3 |
Correct |
41 ms |
63340 KB |
Output is correct |
4 |
Correct |
38 ms |
62976 KB |
Output is correct |
5 |
Correct |
40 ms |
63084 KB |
Output is correct |
6 |
Correct |
40 ms |
63340 KB |
Output is correct |
7 |
Correct |
39 ms |
63084 KB |
Output is correct |
8 |
Correct |
44 ms |
63212 KB |
Output is correct |
9 |
Correct |
41 ms |
63340 KB |
Output is correct |
10 |
Correct |
41 ms |
63348 KB |
Output is correct |
11 |
Correct |
42 ms |
63340 KB |
Output is correct |
12 |
Correct |
46 ms |
63724 KB |
Output is correct |
13 |
Correct |
46 ms |
63724 KB |
Output is correct |
14 |
Correct |
46 ms |
63468 KB |
Output is correct |
15 |
Correct |
44 ms |
63724 KB |
Output is correct |
16 |
Correct |
49 ms |
63596 KB |
Output is correct |
17 |
Correct |
46 ms |
63724 KB |
Output is correct |
18 |
Correct |
49 ms |
64000 KB |
Output is correct |
19 |
Correct |
45 ms |
63596 KB |
Output is correct |
20 |
Correct |
46 ms |
63852 KB |
Output is correct |
21 |
Correct |
59 ms |
64928 KB |
Output is correct |
22 |
Correct |
73 ms |
65764 KB |
Output is correct |
23 |
Correct |
81 ms |
66660 KB |
Output is correct |
24 |
Correct |
125 ms |
67556 KB |
Output is correct |
25 |
Correct |
59 ms |
65516 KB |
Output is correct |
26 |
Correct |
115 ms |
68452 KB |
Output is correct |
27 |
Correct |
90 ms |
67808 KB |
Output is correct |
28 |
Correct |
138 ms |
69216 KB |
Output is correct |
29 |
Correct |
100 ms |
67432 KB |
Output is correct |
30 |
Correct |
116 ms |
68584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
62956 KB |
Output is correct |
2 |
Correct |
41 ms |
63212 KB |
Output is correct |
3 |
Correct |
41 ms |
63340 KB |
Output is correct |
4 |
Correct |
38 ms |
62976 KB |
Output is correct |
5 |
Correct |
40 ms |
63084 KB |
Output is correct |
6 |
Correct |
40 ms |
63340 KB |
Output is correct |
7 |
Correct |
39 ms |
63084 KB |
Output is correct |
8 |
Correct |
44 ms |
63212 KB |
Output is correct |
9 |
Correct |
41 ms |
63340 KB |
Output is correct |
10 |
Correct |
41 ms |
63348 KB |
Output is correct |
11 |
Correct |
460 ms |
85332 KB |
Output is correct |
12 |
Correct |
1756 ms |
110060 KB |
Output is correct |
13 |
Correct |
2023 ms |
117424 KB |
Output is correct |
14 |
Correct |
1143 ms |
106312 KB |
Output is correct |
15 |
Correct |
1171 ms |
119572 KB |
Output is correct |
16 |
Correct |
1120 ms |
117972 KB |
Output is correct |
17 |
Correct |
1929 ms |
128596 KB |
Output is correct |
18 |
Correct |
1989 ms |
130460 KB |
Output is correct |
19 |
Correct |
2154 ms |
135056 KB |
Output is correct |
20 |
Correct |
766 ms |
116688 KB |
Output is correct |
21 |
Correct |
42 ms |
63340 KB |
Output is correct |
22 |
Correct |
46 ms |
63724 KB |
Output is correct |
23 |
Correct |
46 ms |
63724 KB |
Output is correct |
24 |
Correct |
46 ms |
63468 KB |
Output is correct |
25 |
Correct |
44 ms |
63724 KB |
Output is correct |
26 |
Correct |
49 ms |
63596 KB |
Output is correct |
27 |
Correct |
46 ms |
63724 KB |
Output is correct |
28 |
Correct |
49 ms |
64000 KB |
Output is correct |
29 |
Correct |
45 ms |
63596 KB |
Output is correct |
30 |
Correct |
46 ms |
63852 KB |
Output is correct |
31 |
Correct |
59 ms |
64928 KB |
Output is correct |
32 |
Correct |
73 ms |
65764 KB |
Output is correct |
33 |
Correct |
81 ms |
66660 KB |
Output is correct |
34 |
Correct |
125 ms |
67556 KB |
Output is correct |
35 |
Correct |
59 ms |
65516 KB |
Output is correct |
36 |
Correct |
115 ms |
68452 KB |
Output is correct |
37 |
Correct |
90 ms |
67808 KB |
Output is correct |
38 |
Correct |
138 ms |
69216 KB |
Output is correct |
39 |
Correct |
100 ms |
67432 KB |
Output is correct |
40 |
Correct |
116 ms |
68584 KB |
Output is correct |
41 |
Correct |
262 ms |
78556 KB |
Output is correct |
42 |
Correct |
895 ms |
105632 KB |
Output is correct |
43 |
Correct |
366 ms |
88676 KB |
Output is correct |
44 |
Correct |
1308 ms |
128332 KB |
Output is correct |
45 |
Correct |
1299 ms |
118128 KB |
Output is correct |
46 |
Correct |
747 ms |
110792 KB |
Output is correct |
47 |
Correct |
1038 ms |
111660 KB |
Output is correct |
48 |
Correct |
840 ms |
108032 KB |
Output is correct |
49 |
Correct |
759 ms |
108616 KB |
Output is correct |
50 |
Correct |
863 ms |
108004 KB |
Output is correct |
51 |
Correct |
500 ms |
88592 KB |
Output is correct |
52 |
Correct |
1178 ms |
116232 KB |
Output is correct |
53 |
Correct |
890 ms |
108620 KB |
Output is correct |
54 |
Correct |
1832 ms |
122252 KB |
Output is correct |
55 |
Correct |
2019 ms |
126996 KB |
Output is correct |