#include <bits/stdc++.h>
using namespace std;
struct DSU{
int n, check, idx, cnt, mxdeg;
vector<int> lab, deg;
void init(int _n){
n=_n; check=1; idx=-1; cnt=0; mxdeg=0;
lab.assign(n+1, -1);
deg.assign(n+1, 0);
}
int find_set(int u){
return lab[u]<0?u:lab[u]=find_set(lab[u]);
}
void union_sets(int u, int v){
++deg[u], ++deg[v]; mxdeg=max({mxdeg, deg[u], deg[v]});
u=find_set(u); v=find_set(v);
if (u!=v){
if (lab[u]>lab[v]) swap(u, v);
lab[u]+=lab[v];
lab[v]=u;
if (idx==v) idx=u;
}else check=0, idx=u, ++cnt;
}
} dsu[20], dsu2, dsu3;
const int N=1e6+10;
int n, deg[N];
set<int> st3, st4;
vector<pair<int, int>> edge;
bool cc;
vector<int> cand, g[N];
void Init(int N_) {
n=N_;
dsu2.init(n+1);
dsu3.init(n+1);
}
void add_cand(int u){
if (find(cand.begin(), cand.end(), u)!=cand.end() || (int)cand.size()>20) return;
int id=cand.size();
cand.push_back(u);
if (id<20){
dsu[id].init(n+1);
for (auto &i:edge) if (i.first!=u && i.second!=u) dsu[id].union_sets(i.first, i.second);
}
}
void Link(int u, int v) {
++u; ++v;
edge.emplace_back(u, v);
if ((int)cand.size()<=20){
for (int i=0; i<(int)cand.size(); ++i){
if (u==cand[i] || v==cand[i]) continue;
dsu[i].union_sets(u, v);
}
}
if (dsu3.n && (int)st4.size()==1){
if (u!=*st4.begin() && v!=*st4.begin()){
dsu3.union_sets(u, v);
}
}
dsu2.union_sets(u, v);
st3.erase(u); st3.erase(v);
++deg[u]; ++deg[v];
g[u].push_back(v);
g[v].push_back(u);
if (deg[u]==3) st3.insert(u);
if (deg[v]==3) st3.insert(v);
if (deg[u]==4) st4.insert(u);
if (deg[v]==4) st4.insert(v);
if (deg[u]<deg[v]) swap(u, v);
if (deg[u]==4 && (int)st4.size()==1){
dsu3.init(n+1);
for (auto &i:edge){
if (i.first!=u && i.second!=u){
dsu3.union_sets(i.first, i.second);
}
}
}
if ((int)st3.size()+(int)st4.size()<=10){
for (int u:st4) add_cand(u);
for (int u:st3){
add_cand(u);
for (int v:g[u]) add_cand(v);
}
}
}
int CountCritical() {
if (st3.empty() && st4.empty()){
if (dsu2.check) return n;
if (dsu2.cnt==1) return -dsu2.lab[dsu2.idx];
return 0;
}
int ans=0;
if ((int)cand.size()<=20){
for (int i=0; i<(int)cand.size(); ++i){
ans+=dsu[i].check && dsu[i].mxdeg<=2;
}
}else if ((int)st4.size()==1){
ans+=dsu3.check && dsu3.mxdeg<=2;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25176 KB |
Output is correct |
2 |
Correct |
7 ms |
25436 KB |
Output is correct |
3 |
Correct |
6 ms |
25688 KB |
Output is correct |
4 |
Correct |
4 ms |
25180 KB |
Output is correct |
5 |
Correct |
4 ms |
25436 KB |
Output is correct |
6 |
Correct |
6 ms |
25436 KB |
Output is correct |
7 |
Correct |
4 ms |
26148 KB |
Output is correct |
8 |
Correct |
5 ms |
25436 KB |
Output is correct |
9 |
Correct |
6 ms |
25828 KB |
Output is correct |
10 |
Correct |
6 ms |
25692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
55752 KB |
Output is correct |
2 |
Correct |
711 ms |
96952 KB |
Output is correct |
3 |
Correct |
1230 ms |
248240 KB |
Output is correct |
4 |
Correct |
532 ms |
82352 KB |
Output is correct |
5 |
Correct |
542 ms |
82356 KB |
Output is correct |
6 |
Correct |
522 ms |
81220 KB |
Output is correct |
7 |
Correct |
1176 ms |
246496 KB |
Output is correct |
8 |
Correct |
843 ms |
122548 KB |
Output is correct |
9 |
Correct |
906 ms |
137072 KB |
Output is correct |
10 |
Correct |
447 ms |
80568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25176 KB |
Output is correct |
2 |
Correct |
7 ms |
25436 KB |
Output is correct |
3 |
Correct |
6 ms |
25688 KB |
Output is correct |
4 |
Correct |
4 ms |
25180 KB |
Output is correct |
5 |
Correct |
4 ms |
25436 KB |
Output is correct |
6 |
Correct |
6 ms |
25436 KB |
Output is correct |
7 |
Correct |
4 ms |
26148 KB |
Output is correct |
8 |
Correct |
5 ms |
25436 KB |
Output is correct |
9 |
Correct |
6 ms |
25828 KB |
Output is correct |
10 |
Correct |
6 ms |
25692 KB |
Output is correct |
11 |
Correct |
7 ms |
26200 KB |
Output is correct |
12 |
Correct |
9 ms |
27228 KB |
Output is correct |
13 |
Correct |
10 ms |
27264 KB |
Output is correct |
14 |
Correct |
8 ms |
27228 KB |
Output is correct |
15 |
Correct |
9 ms |
29020 KB |
Output is correct |
16 |
Correct |
7 ms |
25944 KB |
Output is correct |
17 |
Correct |
8 ms |
27388 KB |
Output is correct |
18 |
Correct |
11 ms |
29276 KB |
Output is correct |
19 |
Correct |
7 ms |
25848 KB |
Output is correct |
20 |
Correct |
8 ms |
26484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25176 KB |
Output is correct |
2 |
Correct |
7 ms |
25436 KB |
Output is correct |
3 |
Correct |
6 ms |
25688 KB |
Output is correct |
4 |
Correct |
4 ms |
25180 KB |
Output is correct |
5 |
Correct |
4 ms |
25436 KB |
Output is correct |
6 |
Correct |
6 ms |
25436 KB |
Output is correct |
7 |
Correct |
4 ms |
26148 KB |
Output is correct |
8 |
Correct |
5 ms |
25436 KB |
Output is correct |
9 |
Correct |
6 ms |
25828 KB |
Output is correct |
10 |
Correct |
6 ms |
25692 KB |
Output is correct |
11 |
Correct |
7 ms |
26200 KB |
Output is correct |
12 |
Correct |
9 ms |
27228 KB |
Output is correct |
13 |
Correct |
10 ms |
27264 KB |
Output is correct |
14 |
Correct |
8 ms |
27228 KB |
Output is correct |
15 |
Correct |
9 ms |
29020 KB |
Output is correct |
16 |
Correct |
7 ms |
25944 KB |
Output is correct |
17 |
Correct |
8 ms |
27388 KB |
Output is correct |
18 |
Correct |
11 ms |
29276 KB |
Output is correct |
19 |
Correct |
7 ms |
25848 KB |
Output is correct |
20 |
Correct |
8 ms |
26484 KB |
Output is correct |
21 |
Correct |
16 ms |
27604 KB |
Output is correct |
22 |
Correct |
22 ms |
28888 KB |
Output is correct |
23 |
Correct |
28 ms |
29904 KB |
Output is correct |
24 |
Correct |
60 ms |
44492 KB |
Output is correct |
25 |
Correct |
21 ms |
42876 KB |
Output is correct |
26 |
Correct |
54 ms |
39880 KB |
Output is correct |
27 |
Correct |
35 ms |
30916 KB |
Output is correct |
28 |
Correct |
50 ms |
45000 KB |
Output is correct |
29 |
Correct |
36 ms |
45012 KB |
Output is correct |
30 |
Correct |
33 ms |
31772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25176 KB |
Output is correct |
2 |
Correct |
7 ms |
25436 KB |
Output is correct |
3 |
Correct |
6 ms |
25688 KB |
Output is correct |
4 |
Correct |
4 ms |
25180 KB |
Output is correct |
5 |
Correct |
4 ms |
25436 KB |
Output is correct |
6 |
Correct |
6 ms |
25436 KB |
Output is correct |
7 |
Correct |
4 ms |
26148 KB |
Output is correct |
8 |
Correct |
5 ms |
25436 KB |
Output is correct |
9 |
Correct |
6 ms |
25828 KB |
Output is correct |
10 |
Correct |
6 ms |
25692 KB |
Output is correct |
11 |
Correct |
254 ms |
55752 KB |
Output is correct |
12 |
Correct |
711 ms |
96952 KB |
Output is correct |
13 |
Correct |
1230 ms |
248240 KB |
Output is correct |
14 |
Correct |
532 ms |
82352 KB |
Output is correct |
15 |
Correct |
542 ms |
82356 KB |
Output is correct |
16 |
Correct |
522 ms |
81220 KB |
Output is correct |
17 |
Correct |
1176 ms |
246496 KB |
Output is correct |
18 |
Correct |
843 ms |
122548 KB |
Output is correct |
19 |
Correct |
906 ms |
137072 KB |
Output is correct |
20 |
Correct |
447 ms |
80568 KB |
Output is correct |
21 |
Correct |
7 ms |
26200 KB |
Output is correct |
22 |
Correct |
9 ms |
27228 KB |
Output is correct |
23 |
Correct |
10 ms |
27264 KB |
Output is correct |
24 |
Correct |
8 ms |
27228 KB |
Output is correct |
25 |
Correct |
9 ms |
29020 KB |
Output is correct |
26 |
Correct |
7 ms |
25944 KB |
Output is correct |
27 |
Correct |
8 ms |
27388 KB |
Output is correct |
28 |
Correct |
11 ms |
29276 KB |
Output is correct |
29 |
Correct |
7 ms |
25848 KB |
Output is correct |
30 |
Correct |
8 ms |
26484 KB |
Output is correct |
31 |
Correct |
16 ms |
27604 KB |
Output is correct |
32 |
Correct |
22 ms |
28888 KB |
Output is correct |
33 |
Correct |
28 ms |
29904 KB |
Output is correct |
34 |
Correct |
60 ms |
44492 KB |
Output is correct |
35 |
Correct |
21 ms |
42876 KB |
Output is correct |
36 |
Correct |
54 ms |
39880 KB |
Output is correct |
37 |
Correct |
35 ms |
30916 KB |
Output is correct |
38 |
Correct |
50 ms |
45000 KB |
Output is correct |
39 |
Correct |
36 ms |
45012 KB |
Output is correct |
40 |
Correct |
33 ms |
31772 KB |
Output is correct |
41 |
Correct |
123 ms |
48760 KB |
Output is correct |
42 |
Correct |
306 ms |
92860 KB |
Output is correct |
43 |
Correct |
180 ms |
194504 KB |
Output is correct |
44 |
Correct |
531 ms |
233784 KB |
Output is correct |
45 |
Correct |
768 ms |
240060 KB |
Output is correct |
46 |
Correct |
357 ms |
84916 KB |
Output is correct |
47 |
Correct |
488 ms |
87216 KB |
Output is correct |
48 |
Correct |
407 ms |
227136 KB |
Output is correct |
49 |
Correct |
338 ms |
86448 KB |
Output is correct |
50 |
Correct |
362 ms |
84400 KB |
Output is correct |
51 |
Correct |
225 ms |
173004 KB |
Output is correct |
52 |
Correct |
428 ms |
193712 KB |
Output is correct |
53 |
Correct |
424 ms |
228356 KB |
Output is correct |
54 |
Correct |
801 ms |
128064 KB |
Output is correct |
55 |
Correct |
881 ms |
116332 KB |
Output is correct |