#include<bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
using namespace std;
template <typename T>
using matrix = vector<vector<T>>;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const double EPS = 1e-7;
const int MOD = 1e9 + 7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
const int MAXN = 1e6+1;
struct UnionFind{
bool good = 1;
int root;
vector<int> pai, degree;
UnionFind(int n = 0, int start = 0){
root = start;
pai = vector<int>(n+1);
iota(all(pai),0);
degree = vector<int>(n+1);
}
int find (int id){
if(pai[id] == id)
return id;
return pai[id] = find(pai[id]);
}
void onion(int a, int b){
if(a == root || b == root)
return;
//cout << root << " push(" << a << ',' << b << ")\n";
degree[a]++;
degree[b]++;
if(degree[a] == 3)
good = 0;//, cout << "=>" << root << " bad " << a << "\n";
if(degree[b] == 3)
good = 0;//, cout << "=>" << root << " bad " << b << "\n";
a = find(a), b = find(b);
if(a!=b){
pai[b] = a;
} else {
good = 0;//, cout << "=>" << root << " badc\n";
}
}
};
struct UnionFind2{
int cycle = -1;
int cyclect = 0;
vector<int> pai, sizee;
UnionFind2(int n = 0){
pai = vector<int>(n+1);
sizee = vector<int> (n+1,1);
iota(all(pai),0);
}
int find (int id){
if(pai[id] == id)
return id;
return pai[id] = find(pai[id]);
}
void onion(int a, int b){
a = find(a), b = find(b);
if(a == b){
cycle = a;
cyclect++;
} else{
sizee[a] += sizee[b];
pai[b] = a;
}
}
} ufsmall;
int n;
matrix<int> g;
vector<int> cand;
vector<UnionFind> uf;
int mode = 0;
int mode2big;
void inituf(int x, int y){
if(mode < 2)
for(int i : g[x]){
if(cand[i]!=-1)
continue;
cand[i] = uf.size();
uf.push_back(UnionFind(n,i));
for(int j = 0; j < n; j++){
for(int k : g[j]){
if(j > k)
continue;
int a = j , b = k;
if(!(a == min(x,y) && b == max(x,y)))
uf.back().onion(j,k);
}
}
}
if(cand[x]==-1){
cand[x] = uf.size();
uf.push_back(UnionFind(n,x));
for(int j = 0; j < n; j++){
for(int k : g[j]){
if(j > k)
continue;
int a = j , b = k;
if(!(a == min(x,y) && b == max(x,y)))
uf.back().onion(j,k);
}
}
}
}
void Init(int N_) {
n = N_;
g = matrix<int>(n+1);
cand = vector<int>(n+1,-1);
ufsmall = UnionFind2(n);
}
void Link(int A, int B) {
if(mode == 3)
return;
g[A].push_back(B);
g[B].push_back(A);
if(g[A].size() == 4){
if(mode == 2){
mode = 3;
return;
}else mode2big = A, mode = 2, uf.clear(), fill(all(cand),-1), inituf(A,B);
}
if(g[B].size() == 4){
if(mode == 2){
mode = 3;
return;
}else mode2big = B, mode = 2, uf.clear(), fill(all(cand),-1), inituf(B,A);
}
if(g[A].size() == 3 && mode < 2){
mode = 1;
inituf(A,B);
}
if(g[B].size() == 3 && mode < 2){
mode = 1;
inituf(B,A);
}
if(mode == 0){
ufsmall.onion(A,B);
if(ufsmall.cyclect >= 2)
mode = 3;
}
if(uf.size() > 20){
mode = 3;
return;
}
for(auto& i : uf){
i.onion(A,B);
}
}
int CountCritical() {
if(mode == 3)
return 0;
if(mode == 0){
if(ufsmall.cyclect == 0)
return n;
assert(ufsmall.cycle >= 0);
return ufsmall.sizee[ufsmall.cycle];
}
int resp =0;
for(auto& i : uf){
//cout << "->" << i.root << ' ' << i.good << '\n';
resp+=i.good;
}
return resp;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
1364 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
912 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
380 ms |
34840 KB |
Output is correct |
2 |
Correct |
1041 ms |
68608 KB |
Output is correct |
3 |
Correct |
339 ms |
130304 KB |
Output is correct |
4 |
Correct |
984 ms |
66740 KB |
Output is correct |
5 |
Correct |
1004 ms |
66732 KB |
Output is correct |
6 |
Correct |
982 ms |
65520 KB |
Output is correct |
7 |
Correct |
418 ms |
236328 KB |
Output is correct |
8 |
Correct |
2028 ms |
118940 KB |
Output is correct |
9 |
Correct |
2283 ms |
134988 KB |
Output is correct |
10 |
Correct |
684 ms |
77688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
1364 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
912 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
6 ms |
1620 KB |
Output is correct |
12 |
Correct |
15 ms |
2668 KB |
Output is correct |
13 |
Correct |
7 ms |
1620 KB |
Output is correct |
14 |
Correct |
4 ms |
980 KB |
Output is correct |
15 |
Correct |
4 ms |
1620 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
5 ms |
2516 KB |
Output is correct |
18 |
Correct |
7 ms |
4820 KB |
Output is correct |
19 |
Correct |
4 ms |
980 KB |
Output is correct |
20 |
Correct |
7 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
1364 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
912 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
6 ms |
1620 KB |
Output is correct |
12 |
Correct |
15 ms |
2668 KB |
Output is correct |
13 |
Correct |
7 ms |
1620 KB |
Output is correct |
14 |
Correct |
4 ms |
980 KB |
Output is correct |
15 |
Correct |
4 ms |
1620 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
5 ms |
2516 KB |
Output is correct |
18 |
Correct |
7 ms |
4820 KB |
Output is correct |
19 |
Correct |
4 ms |
980 KB |
Output is correct |
20 |
Correct |
7 ms |
1492 KB |
Output is correct |
21 |
Correct |
16 ms |
3092 KB |
Output is correct |
22 |
Correct |
26 ms |
4692 KB |
Output is correct |
23 |
Correct |
44 ms |
5920 KB |
Output is correct |
24 |
Correct |
35 ms |
6484 KB |
Output is correct |
25 |
Correct |
15 ms |
6868 KB |
Output is correct |
26 |
Correct |
40 ms |
6740 KB |
Output is correct |
27 |
Correct |
35 ms |
5512 KB |
Output is correct |
28 |
Correct |
40 ms |
21428 KB |
Output is correct |
29 |
Correct |
47 ms |
23608 KB |
Output is correct |
30 |
Correct |
50 ms |
7980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
1364 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
912 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
380 ms |
34840 KB |
Output is correct |
12 |
Correct |
1041 ms |
68608 KB |
Output is correct |
13 |
Correct |
339 ms |
130304 KB |
Output is correct |
14 |
Correct |
984 ms |
66740 KB |
Output is correct |
15 |
Correct |
1004 ms |
66732 KB |
Output is correct |
16 |
Correct |
982 ms |
65520 KB |
Output is correct |
17 |
Correct |
418 ms |
236328 KB |
Output is correct |
18 |
Correct |
2028 ms |
118940 KB |
Output is correct |
19 |
Correct |
2283 ms |
134988 KB |
Output is correct |
20 |
Correct |
684 ms |
77688 KB |
Output is correct |
21 |
Correct |
6 ms |
1620 KB |
Output is correct |
22 |
Correct |
15 ms |
2668 KB |
Output is correct |
23 |
Correct |
7 ms |
1620 KB |
Output is correct |
24 |
Correct |
4 ms |
980 KB |
Output is correct |
25 |
Correct |
4 ms |
1620 KB |
Output is correct |
26 |
Correct |
4 ms |
980 KB |
Output is correct |
27 |
Correct |
5 ms |
2516 KB |
Output is correct |
28 |
Correct |
7 ms |
4820 KB |
Output is correct |
29 |
Correct |
4 ms |
980 KB |
Output is correct |
30 |
Correct |
7 ms |
1492 KB |
Output is correct |
31 |
Correct |
16 ms |
3092 KB |
Output is correct |
32 |
Correct |
26 ms |
4692 KB |
Output is correct |
33 |
Correct |
44 ms |
5920 KB |
Output is correct |
34 |
Correct |
35 ms |
6484 KB |
Output is correct |
35 |
Correct |
15 ms |
6868 KB |
Output is correct |
36 |
Correct |
40 ms |
6740 KB |
Output is correct |
37 |
Correct |
35 ms |
5512 KB |
Output is correct |
38 |
Correct |
40 ms |
21428 KB |
Output is correct |
39 |
Correct |
47 ms |
23608 KB |
Output is correct |
40 |
Correct |
50 ms |
7980 KB |
Output is correct |
41 |
Correct |
198 ms |
29976 KB |
Output is correct |
42 |
Correct |
702 ms |
78808 KB |
Output is correct |
43 |
Correct |
242 ms |
62048 KB |
Output is correct |
44 |
Correct |
323 ms |
149184 KB |
Output is correct |
45 |
Correct |
554 ms |
104488 KB |
Output is correct |
46 |
Correct |
597 ms |
66572 KB |
Output is correct |
47 |
Correct |
884 ms |
68268 KB |
Output is correct |
48 |
Correct |
427 ms |
232180 KB |
Output is correct |
49 |
Correct |
617 ms |
71580 KB |
Output is correct |
50 |
Correct |
677 ms |
70636 KB |
Output is correct |
51 |
Correct |
275 ms |
53100 KB |
Output is correct |
52 |
Correct |
326 ms |
175012 KB |
Output is correct |
53 |
Correct |
402 ms |
231608 KB |
Output is correct |
54 |
Correct |
1781 ms |
109652 KB |
Output is correct |
55 |
Correct |
840 ms |
78100 KB |
Output is correct |