// ~ Be Name Khoda ~ //
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn = 1e6 + 10;
const int maxn5 = 1e6 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e18;
int n;
bool found = false;
bool cy = false, morecy = false, mark[maxn5];
int cynum = 0;
vector <int> adj[maxn5];
struct _dsu{
int remver, par[maxn5];
bool noans;
_dsu(){
remver = -1;
noans = false;
memset(par, -1, sizeof par);
}
int get_par(int a){return par[a] < 0 ? a : par[a] = get_par(par[a]);}
inline void add(int a, int b){
if(a == remver || b == remver || a == b)
return;
//if(remver == 3)
// cout << "here " << a << ' ' << b << endl;
a = get_par(a);
b = get_par(b);
//if(remver == 3)
// cout << "and " << a << ' ' << b << endl;
if(a == b){
noans = true;
if(cy)
morecy = true;
else{
cy = true;
cynum = -par[a];
}
return;
}
if(-par[a] < -par[b])
swap(a, b);
par[a] += par[b];
par[b] = a;
}
} dsu[6];
void Init(int N_) {
n = N_;
}
void Link(int a, int b){
adj[a].pb(b);
adj[b].pb(a);
dsu[0].add(a, b);
if(found) for(int i = 1; i < 5; i++)
dsu[i].add(a, b);
if(!found && adj[a].size() == 3){
found = true;
dsu[1].remver = a;
for(int v = 0; v < n; v++) for(auto u : adj[v]) if(u < v)
dsu[1].add(v, u);
for(int i = 0; i < 3; i++){
dsu[i + 2].remver = adj[a][i];
for(int v = 0; v < n; v++) for(auto u : adj[v]) if(u < v)
dsu[i + 2].add(v, u);
}
}
else if(adj[a].size() == 3){
mark[a] = mark[adj[a][0]] = mark[adj[a][1]] = mark[adj[a][2]] = true;
for(int i = 1; i < 5; i++) if(!mark[dsu[i].remver])
dsu[i].noans = true;
mark[a] = mark[adj[a][0]] = mark[adj[a][1]] = mark[adj[a][2]] = false;
}
else if(adj[a].size() == 4){
for(int i = 1; i < 5; i++) if(dsu[i].remver != a)
dsu[i].noans = true;
}
swap(a, b);
if(!found && adj[a].size() == 3){
found = true;
dsu[1].remver = a;
for(int v = 0; v < n; v++) for(auto u : adj[v]) if(u < v)
dsu[1].add(v, u);
for(int i = 0; i < 3; i++){
dsu[i + 2].remver = adj[a][i];
for(int v = 0; v < n; v++) for(auto u : adj[v]) if(u < v)
dsu[i + 2].add(v, u);
}
}
else if(adj[a].size() == 3){
mark[a] = mark[adj[a][0]] = mark[adj[a][1]] = mark[adj[a][2]] = true;
for(int i = 1; i < 5; i++) if(!mark[dsu[i].remver])
dsu[i].noans = true;
mark[a] = mark[adj[a][0]] = mark[adj[a][1]] = mark[adj[a][2]] = false;
}
else if(adj[a].size() == 4){
for(int i = 1; i < 5; i++) if(dsu[i].remver != a)
dsu[i].noans = true;
}
}
int CountCritical() {
if(found){
int num = 0;
for(int i = 1; i < 5; i++){
num += (!dsu[i].noans);
//cout << i << ' ' << dsu[i].noans << ' ' << dsu[i].remver << endl;
}
return num;
}
if(!cy)
return n;
if(morecy)
return 0;
return cynum;
}
/*
4 7
1 3
1 2
2 3
0 3
0 2
0 1
-1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47216 KB |
Output is correct |
2 |
Correct |
22 ms |
47424 KB |
Output is correct |
3 |
Correct |
21 ms |
47524 KB |
Output is correct |
4 |
Correct |
20 ms |
47264 KB |
Output is correct |
5 |
Correct |
22 ms |
47340 KB |
Output is correct |
6 |
Correct |
22 ms |
47520 KB |
Output is correct |
7 |
Correct |
21 ms |
47184 KB |
Output is correct |
8 |
Correct |
22 ms |
47424 KB |
Output is correct |
9 |
Correct |
22 ms |
47444 KB |
Output is correct |
10 |
Correct |
27 ms |
47464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
210 ms |
64132 KB |
Output is correct |
2 |
Correct |
802 ms |
72772 KB |
Output is correct |
3 |
Correct |
955 ms |
75892 KB |
Output is correct |
4 |
Correct |
667 ms |
78884 KB |
Output is correct |
5 |
Correct |
702 ms |
79408 KB |
Output is correct |
6 |
Correct |
658 ms |
78348 KB |
Output is correct |
7 |
Correct |
918 ms |
75640 KB |
Output is correct |
8 |
Correct |
1006 ms |
77368 KB |
Output is correct |
9 |
Correct |
992 ms |
79232 KB |
Output is correct |
10 |
Correct |
421 ms |
77572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47216 KB |
Output is correct |
2 |
Correct |
22 ms |
47424 KB |
Output is correct |
3 |
Correct |
21 ms |
47524 KB |
Output is correct |
4 |
Correct |
20 ms |
47264 KB |
Output is correct |
5 |
Correct |
22 ms |
47340 KB |
Output is correct |
6 |
Correct |
22 ms |
47520 KB |
Output is correct |
7 |
Correct |
21 ms |
47184 KB |
Output is correct |
8 |
Correct |
22 ms |
47424 KB |
Output is correct |
9 |
Correct |
22 ms |
47444 KB |
Output is correct |
10 |
Correct |
27 ms |
47464 KB |
Output is correct |
11 |
Correct |
26 ms |
47436 KB |
Output is correct |
12 |
Correct |
23 ms |
47628 KB |
Output is correct |
13 |
Correct |
25 ms |
47700 KB |
Output is correct |
14 |
Correct |
22 ms |
47548 KB |
Output is correct |
15 |
Correct |
26 ms |
47440 KB |
Output is correct |
16 |
Correct |
24 ms |
47740 KB |
Output is correct |
17 |
Correct |
24 ms |
47652 KB |
Output is correct |
18 |
Correct |
25 ms |
47820 KB |
Output is correct |
19 |
Correct |
23 ms |
47700 KB |
Output is correct |
20 |
Correct |
24 ms |
47656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47216 KB |
Output is correct |
2 |
Correct |
22 ms |
47424 KB |
Output is correct |
3 |
Correct |
21 ms |
47524 KB |
Output is correct |
4 |
Correct |
20 ms |
47264 KB |
Output is correct |
5 |
Correct |
22 ms |
47340 KB |
Output is correct |
6 |
Correct |
22 ms |
47520 KB |
Output is correct |
7 |
Correct |
21 ms |
47184 KB |
Output is correct |
8 |
Correct |
22 ms |
47424 KB |
Output is correct |
9 |
Correct |
22 ms |
47444 KB |
Output is correct |
10 |
Correct |
27 ms |
47464 KB |
Output is correct |
11 |
Correct |
26 ms |
47436 KB |
Output is correct |
12 |
Correct |
23 ms |
47628 KB |
Output is correct |
13 |
Correct |
25 ms |
47700 KB |
Output is correct |
14 |
Correct |
22 ms |
47548 KB |
Output is correct |
15 |
Correct |
26 ms |
47440 KB |
Output is correct |
16 |
Correct |
24 ms |
47740 KB |
Output is correct |
17 |
Correct |
24 ms |
47652 KB |
Output is correct |
18 |
Correct |
25 ms |
47820 KB |
Output is correct |
19 |
Correct |
23 ms |
47700 KB |
Output is correct |
20 |
Correct |
24 ms |
47656 KB |
Output is correct |
21 |
Correct |
32 ms |
48596 KB |
Output is correct |
22 |
Correct |
41 ms |
49476 KB |
Output is correct |
23 |
Correct |
44 ms |
50028 KB |
Output is correct |
24 |
Correct |
57 ms |
49660 KB |
Output is correct |
25 |
Correct |
30 ms |
47908 KB |
Output is correct |
26 |
Correct |
48 ms |
50212 KB |
Output is correct |
27 |
Correct |
60 ms |
50964 KB |
Output is correct |
28 |
Correct |
49 ms |
51184 KB |
Output is correct |
29 |
Correct |
43 ms |
49576 KB |
Output is correct |
30 |
Correct |
50 ms |
51440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47216 KB |
Output is correct |
2 |
Correct |
22 ms |
47424 KB |
Output is correct |
3 |
Correct |
21 ms |
47524 KB |
Output is correct |
4 |
Correct |
20 ms |
47264 KB |
Output is correct |
5 |
Correct |
22 ms |
47340 KB |
Output is correct |
6 |
Correct |
22 ms |
47520 KB |
Output is correct |
7 |
Correct |
21 ms |
47184 KB |
Output is correct |
8 |
Correct |
22 ms |
47424 KB |
Output is correct |
9 |
Correct |
22 ms |
47444 KB |
Output is correct |
10 |
Correct |
27 ms |
47464 KB |
Output is correct |
11 |
Correct |
210 ms |
64132 KB |
Output is correct |
12 |
Correct |
802 ms |
72772 KB |
Output is correct |
13 |
Correct |
955 ms |
75892 KB |
Output is correct |
14 |
Correct |
667 ms |
78884 KB |
Output is correct |
15 |
Correct |
702 ms |
79408 KB |
Output is correct |
16 |
Correct |
658 ms |
78348 KB |
Output is correct |
17 |
Correct |
918 ms |
75640 KB |
Output is correct |
18 |
Correct |
1006 ms |
77368 KB |
Output is correct |
19 |
Correct |
992 ms |
79232 KB |
Output is correct |
20 |
Correct |
421 ms |
77572 KB |
Output is correct |
21 |
Correct |
26 ms |
47436 KB |
Output is correct |
22 |
Correct |
23 ms |
47628 KB |
Output is correct |
23 |
Correct |
25 ms |
47700 KB |
Output is correct |
24 |
Correct |
22 ms |
47548 KB |
Output is correct |
25 |
Correct |
26 ms |
47440 KB |
Output is correct |
26 |
Correct |
24 ms |
47740 KB |
Output is correct |
27 |
Correct |
24 ms |
47652 KB |
Output is correct |
28 |
Correct |
25 ms |
47820 KB |
Output is correct |
29 |
Correct |
23 ms |
47700 KB |
Output is correct |
30 |
Correct |
24 ms |
47656 KB |
Output is correct |
31 |
Correct |
32 ms |
48596 KB |
Output is correct |
32 |
Correct |
41 ms |
49476 KB |
Output is correct |
33 |
Correct |
44 ms |
50028 KB |
Output is correct |
34 |
Correct |
57 ms |
49660 KB |
Output is correct |
35 |
Correct |
30 ms |
47908 KB |
Output is correct |
36 |
Correct |
48 ms |
50212 KB |
Output is correct |
37 |
Correct |
60 ms |
50964 KB |
Output is correct |
38 |
Correct |
49 ms |
51184 KB |
Output is correct |
39 |
Correct |
43 ms |
49576 KB |
Output is correct |
40 |
Correct |
50 ms |
51440 KB |
Output is correct |
41 |
Correct |
144 ms |
59300 KB |
Output is correct |
42 |
Correct |
410 ms |
70136 KB |
Output is correct |
43 |
Correct |
215 ms |
55268 KB |
Output is correct |
44 |
Correct |
580 ms |
83408 KB |
Output is correct |
45 |
Correct |
655 ms |
76836 KB |
Output is correct |
46 |
Correct |
456 ms |
81292 KB |
Output is correct |
47 |
Correct |
582 ms |
81772 KB |
Output is correct |
48 |
Correct |
431 ms |
71152 KB |
Output is correct |
49 |
Correct |
436 ms |
80120 KB |
Output is correct |
50 |
Correct |
525 ms |
79680 KB |
Output is correct |
51 |
Correct |
246 ms |
57136 KB |
Output is correct |
52 |
Correct |
496 ms |
77904 KB |
Output is correct |
53 |
Correct |
415 ms |
71352 KB |
Output is correct |
54 |
Correct |
815 ms |
79816 KB |
Output is correct |
55 |
Correct |
891 ms |
81612 KB |
Output is correct |