#include <bits/stdc++.h>
using namespace std;
struct ufds{
vector<int> sz, par;
ufds(){}
ufds(int n): sz(n, 1), par(n){
iota(par.begin(), par.end(), 0);
}
int find(int a){
return par[a] == a ? a : par[a] = find(par[a]);
}
int unite(int a, int b){
a = find(a), b = find(b);
if(a == b) return 0;
if(sz[a] < sz[b]) swap(a, b);
par[b] = a;
sz[a] += sz[b];
return 1;
}
};
set<int> ans;
vector<vector<int>> g, tree;
vector<int> deg;
int n = 0;
ufds ds;
int bad = 0;
int d4 = 0;
void Init(int N){
assert(n == 0);
n = N;
g.resize(n);
tree.resize(n);
deg.resize(n);
for(int i = 0; i < n; i++){
ans.insert(i);
}
ds = ufds(n);
}
void proc(int a, int add = 1){
if(deg[a] >= 4){
if(add){
if(deg[a] == 4) d4++;
if(d4 == 2) ans = {};
}
if(!ans.count(a)) ans = {};
else ans = {a};
}else if(deg[a] == 3){
set<int> nans;
if(ans.count(a)) nans.insert(a);
for(int u: g[a]){
if(ans.count(u)) nans.insert(u);
}
ans = nans;
}
}
int CountCritical(){
return ans.size();
}
int cyc = 0;
vector<int> path;
int dfs(int v, int p, int x){
path.push_back(v);
if(v == x) return 1;
for(int u: tree[v]) if(u != p){
if(dfs(u, v, x)) return 1;
}
path.pop_back();
return 0;
}
vector<pair<int,int>> eds;
map<int, ufds> mp;
void Link(int a, int b){
int res = ds.unite(a, b);
deg[a]++, deg[b]++;
g[a].push_back(b);
g[b].push_back(a);
eds.emplace_back(a, b);
proc(a), proc(b);
if(cyc == 2){
set<int> nans;
for(int x: ans){
int tbad = 0;
if(a != x && b != x && !mp[x].unite(a, b)){
tbad = 1;
}
if(!tbad) nans.insert(x);
}
ans = nans;
for(int x: ans){
proc(x, 0);
}
assert(ans.size() <= 2);
}
if(!res){
if(!cyc){
dfs(a, -1, b);
ans = {};
for(int x: path){
ans.insert(x);
}
for(int i = 0; i < n; i++){
proc(i, 0);
}
cyc = 1;
}else{
if(cyc == 1){
set<int> nans;
for(int x: ans) if(deg[x] >= 3){
ufds f(n);
int tbad = 0;
for(auto [u, v]: eds){
if(u != x && v != x){
if(!f.unite(u, v)) tbad = 1;
}
}
if(!tbad) nans.insert(x), mp[x] = f;;
}
ans = nans;
for(int x: ans){
proc(x, 0);
}
}
cyc = 2;
}
}else{
tree[a].push_back(b);
tree[b].push_back(a);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
980 KB |
Output is correct |
3 |
Correct |
3 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
980 KB |
Output is correct |
6 |
Correct |
3 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
5 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
530 ms |
97400 KB |
Output is correct |
2 |
Correct |
1097 ms |
122972 KB |
Output is correct |
3 |
Correct |
1256 ms |
132024 KB |
Output is correct |
4 |
Correct |
1453 ms |
188696 KB |
Output is correct |
5 |
Correct |
1431 ms |
190604 KB |
Output is correct |
6 |
Correct |
1675 ms |
219616 KB |
Output is correct |
7 |
Correct |
1282 ms |
130672 KB |
Output is correct |
8 |
Correct |
1273 ms |
171008 KB |
Output is correct |
9 |
Correct |
1390 ms |
187220 KB |
Output is correct |
10 |
Correct |
990 ms |
184344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
980 KB |
Output is correct |
3 |
Correct |
3 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
980 KB |
Output is correct |
6 |
Correct |
3 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
5 ms |
1236 KB |
Output is correct |
11 |
Correct |
3 ms |
1108 KB |
Output is correct |
12 |
Correct |
5 ms |
2132 KB |
Output is correct |
13 |
Correct |
6 ms |
2004 KB |
Output is correct |
14 |
Correct |
5 ms |
1508 KB |
Output is correct |
15 |
Correct |
6 ms |
2516 KB |
Output is correct |
16 |
Correct |
6 ms |
2132 KB |
Output is correct |
17 |
Correct |
5 ms |
1620 KB |
Output is correct |
18 |
Correct |
7 ms |
2644 KB |
Output is correct |
19 |
Correct |
6 ms |
2260 KB |
Output is correct |
20 |
Correct |
5 ms |
2184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
980 KB |
Output is correct |
3 |
Correct |
3 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
980 KB |
Output is correct |
6 |
Correct |
3 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
5 ms |
1236 KB |
Output is correct |
11 |
Correct |
3 ms |
1108 KB |
Output is correct |
12 |
Correct |
5 ms |
2132 KB |
Output is correct |
13 |
Correct |
6 ms |
2004 KB |
Output is correct |
14 |
Correct |
5 ms |
1508 KB |
Output is correct |
15 |
Correct |
6 ms |
2516 KB |
Output is correct |
16 |
Correct |
6 ms |
2132 KB |
Output is correct |
17 |
Correct |
5 ms |
1620 KB |
Output is correct |
18 |
Correct |
7 ms |
2644 KB |
Output is correct |
19 |
Correct |
6 ms |
2260 KB |
Output is correct |
20 |
Correct |
5 ms |
2184 KB |
Output is correct |
21 |
Correct |
26 ms |
7984 KB |
Output is correct |
22 |
Correct |
40 ms |
12472 KB |
Output is correct |
23 |
Correct |
50 ms |
15684 KB |
Output is correct |
24 |
Correct |
52 ms |
10944 KB |
Output is correct |
25 |
Correct |
28 ms |
11084 KB |
Output is correct |
26 |
Correct |
51 ms |
11340 KB |
Output is correct |
27 |
Correct |
53 ms |
15456 KB |
Output is correct |
28 |
Correct |
55 ms |
12708 KB |
Output is correct |
29 |
Correct |
53 ms |
11912 KB |
Output is correct |
30 |
Correct |
94 ms |
19580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
980 KB |
Output is correct |
3 |
Correct |
3 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
980 KB |
Output is correct |
6 |
Correct |
3 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
4 ms |
1108 KB |
Output is correct |
10 |
Correct |
5 ms |
1236 KB |
Output is correct |
11 |
Correct |
530 ms |
97400 KB |
Output is correct |
12 |
Correct |
1097 ms |
122972 KB |
Output is correct |
13 |
Correct |
1256 ms |
132024 KB |
Output is correct |
14 |
Correct |
1453 ms |
188696 KB |
Output is correct |
15 |
Correct |
1431 ms |
190604 KB |
Output is correct |
16 |
Correct |
1675 ms |
219616 KB |
Output is correct |
17 |
Correct |
1282 ms |
130672 KB |
Output is correct |
18 |
Correct |
1273 ms |
171008 KB |
Output is correct |
19 |
Correct |
1390 ms |
187220 KB |
Output is correct |
20 |
Correct |
990 ms |
184344 KB |
Output is correct |
21 |
Correct |
3 ms |
1108 KB |
Output is correct |
22 |
Correct |
5 ms |
2132 KB |
Output is correct |
23 |
Correct |
6 ms |
2004 KB |
Output is correct |
24 |
Correct |
5 ms |
1508 KB |
Output is correct |
25 |
Correct |
6 ms |
2516 KB |
Output is correct |
26 |
Correct |
6 ms |
2132 KB |
Output is correct |
27 |
Correct |
5 ms |
1620 KB |
Output is correct |
28 |
Correct |
7 ms |
2644 KB |
Output is correct |
29 |
Correct |
6 ms |
2260 KB |
Output is correct |
30 |
Correct |
5 ms |
2184 KB |
Output is correct |
31 |
Correct |
26 ms |
7984 KB |
Output is correct |
32 |
Correct |
40 ms |
12472 KB |
Output is correct |
33 |
Correct |
50 ms |
15684 KB |
Output is correct |
34 |
Correct |
52 ms |
10944 KB |
Output is correct |
35 |
Correct |
28 ms |
11084 KB |
Output is correct |
36 |
Correct |
51 ms |
11340 KB |
Output is correct |
37 |
Correct |
53 ms |
15456 KB |
Output is correct |
38 |
Correct |
55 ms |
12708 KB |
Output is correct |
39 |
Correct |
53 ms |
11912 KB |
Output is correct |
40 |
Correct |
94 ms |
19580 KB |
Output is correct |
41 |
Correct |
324 ms |
73228 KB |
Output is correct |
42 |
Correct |
649 ms |
122072 KB |
Output is correct |
43 |
Correct |
399 ms |
103164 KB |
Output is correct |
44 |
Correct |
983 ms |
129452 KB |
Output is correct |
45 |
Correct |
973 ms |
126740 KB |
Output is correct |
46 |
Correct |
916 ms |
154252 KB |
Output is correct |
47 |
Correct |
1391 ms |
180456 KB |
Output is correct |
48 |
Correct |
713 ms |
115120 KB |
Output is correct |
49 |
Correct |
946 ms |
170672 KB |
Output is correct |
50 |
Correct |
993 ms |
168876 KB |
Output is correct |
51 |
Correct |
458 ms |
88832 KB |
Output is correct |
52 |
Correct |
840 ms |
104752 KB |
Output is correct |
53 |
Correct |
674 ms |
113736 KB |
Output is correct |
54 |
Correct |
1185 ms |
134584 KB |
Output is correct |
55 |
Correct |
1234 ms |
126108 KB |
Output is correct |