#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
vector<int> graph[1000005];
int n;
int deg[1000005];
int focus = -1;
bool deadend = 0;
int v[4];
int bad[4];
struct disj{
int pa[1000005];
int deg2[1000005];
int deg3[1000005];
int degx[1000005];
int size[1000005];
int without;
void init(int n, int w){
without = w;
for(int i=0; i<=n; i++) pa[i] = i, size[i] = 1;
}
int find(int x){
return pa[x] = (pa[x] == x ? x : find(pa[x]));
}
void uni(int p, int q){
if(p == without || q == without) return;
degx[p]++;
int px = find(p), qx = find(q);
if(degx[p] == 2){
deg2[px]++;
}
if(degx[p] == 3){
deg3[px]++;
}
degx[q]++;
if(degx[q] == 2){
deg2[qx]++;
}
if(degx[q] == 3){
deg3[qx]++;
}
p = px, q = qx;
if(p == q) return;
pa[q] = p;
deg2[p] += deg2[q];
deg3[p] += deg3[q];
size[p] += size[q];
}
bool ckBad(int x){
x = find(x);
return (deg3[x] || (deg2[x] == size[x]));
}
}disj, wotree[4];
void Init(int N){
n = N;
memset(v,-1,sizeof(v));
disj.init(n,-1);
}
void Link(int A, int B){
deg[A]++, deg[B]++;
if(deg[A] <= deg[B]){
swap(A,B);
}
if(deg[A] == 3 && v[0] == -1){
v[0] = A;
v[1] = B;
v[2] = graph[A][0];
v[3] = graph[A][1];
for(int i=0; i<4; i++){
wotree[i].init(n,v[i]);
for(int j=0; j<n; j++){
for(auto &k : graph[j]){
if(j < k) wotree[i].uni(j,k);
}
if(j != v[i] && wotree[i].ckBad(j)){
bad[i] = 1;
break;
}
}
}
}
graph[A].push_back(B);
graph[B].push_back(A);
disj.uni(A,B);
if(v[0] == -1){
if(disj.ckBad(A)){
if(focus == -1){
focus = A;
}
else if(disj.find(focus) != disj.find(A)){
deadend = 1;
}
}
}
else{
for(int i=0; i<4; i++){
if(bad[i]) continue;
wotree[i].uni(A,B);
if(wotree[i].ckBad(A)){
bad[i] = 1;
}
}
}
}
int CountCritical(){
if(deadend == 1) return 0;
if(disj.without != -1) return 1;
else if(v[0] != -1){
int cnt = 0;
for(int i=0; i<4; i++){
if(!bad[i]) cnt++;
}
return cnt;
}
else{
if(focus == -1) return n;
return disj.size[disj.find(focus)];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24564 KB |
Output is correct |
3 |
Correct |
26 ms |
24840 KB |
Output is correct |
4 |
Correct |
22 ms |
24840 KB |
Output is correct |
5 |
Correct |
24 ms |
24840 KB |
Output is correct |
6 |
Correct |
26 ms |
24840 KB |
Output is correct |
7 |
Correct |
25 ms |
24840 KB |
Output is correct |
8 |
Correct |
24 ms |
24840 KB |
Output is correct |
9 |
Correct |
26 ms |
24840 KB |
Output is correct |
10 |
Correct |
26 ms |
24988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
661 ms |
52668 KB |
Output is correct |
2 |
Correct |
2260 ms |
130580 KB |
Output is correct |
3 |
Correct |
1630 ms |
152288 KB |
Output is correct |
4 |
Correct |
1658 ms |
152288 KB |
Output is correct |
5 |
Correct |
1650 ms |
152288 KB |
Output is correct |
6 |
Correct |
1781 ms |
152288 KB |
Output is correct |
7 |
Correct |
1746 ms |
152288 KB |
Output is correct |
8 |
Correct |
3036 ms |
152288 KB |
Output is correct |
9 |
Correct |
3209 ms |
157244 KB |
Output is correct |
10 |
Correct |
1008 ms |
157244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24564 KB |
Output is correct |
3 |
Correct |
26 ms |
24840 KB |
Output is correct |
4 |
Correct |
22 ms |
24840 KB |
Output is correct |
5 |
Correct |
24 ms |
24840 KB |
Output is correct |
6 |
Correct |
26 ms |
24840 KB |
Output is correct |
7 |
Correct |
25 ms |
24840 KB |
Output is correct |
8 |
Correct |
24 ms |
24840 KB |
Output is correct |
9 |
Correct |
26 ms |
24840 KB |
Output is correct |
10 |
Correct |
26 ms |
24988 KB |
Output is correct |
11 |
Correct |
32 ms |
157244 KB |
Output is correct |
12 |
Correct |
34 ms |
157244 KB |
Output is correct |
13 |
Correct |
32 ms |
157244 KB |
Output is correct |
14 |
Correct |
28 ms |
157244 KB |
Output is correct |
15 |
Correct |
32 ms |
157244 KB |
Output is correct |
16 |
Correct |
40 ms |
157244 KB |
Output is correct |
17 |
Correct |
28 ms |
157244 KB |
Output is correct |
18 |
Correct |
31 ms |
157244 KB |
Output is correct |
19 |
Correct |
28 ms |
157244 KB |
Output is correct |
20 |
Correct |
32 ms |
157244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24564 KB |
Output is correct |
3 |
Correct |
26 ms |
24840 KB |
Output is correct |
4 |
Correct |
22 ms |
24840 KB |
Output is correct |
5 |
Correct |
24 ms |
24840 KB |
Output is correct |
6 |
Correct |
26 ms |
24840 KB |
Output is correct |
7 |
Correct |
25 ms |
24840 KB |
Output is correct |
8 |
Correct |
24 ms |
24840 KB |
Output is correct |
9 |
Correct |
26 ms |
24840 KB |
Output is correct |
10 |
Correct |
26 ms |
24988 KB |
Output is correct |
11 |
Correct |
32 ms |
157244 KB |
Output is correct |
12 |
Correct |
34 ms |
157244 KB |
Output is correct |
13 |
Correct |
32 ms |
157244 KB |
Output is correct |
14 |
Correct |
28 ms |
157244 KB |
Output is correct |
15 |
Correct |
32 ms |
157244 KB |
Output is correct |
16 |
Correct |
40 ms |
157244 KB |
Output is correct |
17 |
Correct |
28 ms |
157244 KB |
Output is correct |
18 |
Correct |
31 ms |
157244 KB |
Output is correct |
19 |
Correct |
28 ms |
157244 KB |
Output is correct |
20 |
Correct |
32 ms |
157244 KB |
Output is correct |
21 |
Correct |
47 ms |
157244 KB |
Output is correct |
22 |
Correct |
60 ms |
157244 KB |
Output is correct |
23 |
Correct |
71 ms |
157244 KB |
Output is correct |
24 |
Correct |
90 ms |
157244 KB |
Output is correct |
25 |
Correct |
45 ms |
157244 KB |
Output is correct |
26 |
Correct |
93 ms |
157244 KB |
Output is correct |
27 |
Correct |
81 ms |
157244 KB |
Output is correct |
28 |
Correct |
88 ms |
157244 KB |
Output is correct |
29 |
Correct |
71 ms |
157244 KB |
Output is correct |
30 |
Correct |
89 ms |
157244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
24564 KB |
Output is correct |
3 |
Correct |
26 ms |
24840 KB |
Output is correct |
4 |
Correct |
22 ms |
24840 KB |
Output is correct |
5 |
Correct |
24 ms |
24840 KB |
Output is correct |
6 |
Correct |
26 ms |
24840 KB |
Output is correct |
7 |
Correct |
25 ms |
24840 KB |
Output is correct |
8 |
Correct |
24 ms |
24840 KB |
Output is correct |
9 |
Correct |
26 ms |
24840 KB |
Output is correct |
10 |
Correct |
26 ms |
24988 KB |
Output is correct |
11 |
Correct |
661 ms |
52668 KB |
Output is correct |
12 |
Correct |
2260 ms |
130580 KB |
Output is correct |
13 |
Correct |
1630 ms |
152288 KB |
Output is correct |
14 |
Correct |
1658 ms |
152288 KB |
Output is correct |
15 |
Correct |
1650 ms |
152288 KB |
Output is correct |
16 |
Correct |
1781 ms |
152288 KB |
Output is correct |
17 |
Correct |
1746 ms |
152288 KB |
Output is correct |
18 |
Correct |
3036 ms |
152288 KB |
Output is correct |
19 |
Correct |
3209 ms |
157244 KB |
Output is correct |
20 |
Correct |
1008 ms |
157244 KB |
Output is correct |
21 |
Correct |
32 ms |
157244 KB |
Output is correct |
22 |
Correct |
34 ms |
157244 KB |
Output is correct |
23 |
Correct |
32 ms |
157244 KB |
Output is correct |
24 |
Correct |
28 ms |
157244 KB |
Output is correct |
25 |
Correct |
32 ms |
157244 KB |
Output is correct |
26 |
Correct |
40 ms |
157244 KB |
Output is correct |
27 |
Correct |
28 ms |
157244 KB |
Output is correct |
28 |
Correct |
31 ms |
157244 KB |
Output is correct |
29 |
Correct |
28 ms |
157244 KB |
Output is correct |
30 |
Correct |
32 ms |
157244 KB |
Output is correct |
31 |
Correct |
47 ms |
157244 KB |
Output is correct |
32 |
Correct |
60 ms |
157244 KB |
Output is correct |
33 |
Correct |
71 ms |
157244 KB |
Output is correct |
34 |
Correct |
90 ms |
157244 KB |
Output is correct |
35 |
Correct |
45 ms |
157244 KB |
Output is correct |
36 |
Correct |
93 ms |
157244 KB |
Output is correct |
37 |
Correct |
81 ms |
157244 KB |
Output is correct |
38 |
Correct |
88 ms |
157244 KB |
Output is correct |
39 |
Correct |
71 ms |
157244 KB |
Output is correct |
40 |
Correct |
89 ms |
157244 KB |
Output is correct |
41 |
Correct |
293 ms |
157244 KB |
Output is correct |
42 |
Correct |
1459 ms |
157244 KB |
Output is correct |
43 |
Correct |
405 ms |
157244 KB |
Output is correct |
44 |
Correct |
1028 ms |
157244 KB |
Output is correct |
45 |
Correct |
1396 ms |
157244 KB |
Output is correct |
46 |
Correct |
1006 ms |
157244 KB |
Output is correct |
47 |
Correct |
1285 ms |
157244 KB |
Output is correct |
48 |
Correct |
796 ms |
157244 KB |
Output is correct |
49 |
Correct |
1048 ms |
157244 KB |
Output is correct |
50 |
Correct |
1071 ms |
157244 KB |
Output is correct |
51 |
Correct |
497 ms |
157244 KB |
Output is correct |
52 |
Correct |
879 ms |
157244 KB |
Output is correct |
53 |
Correct |
836 ms |
157244 KB |
Output is correct |
54 |
Correct |
2843 ms |
157244 KB |
Output is correct |
55 |
Correct |
2077 ms |
157244 KB |
Output is correct |