#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
int& ckmax(int& a, int b){
a = max(a, b);
return a;
}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int mx = 1000005;
int N;
vpi eds;
vi cands;
int max_deg;
int deg[mx];
pi beg_other_end[mx]; //other end, cycle size
int cyc_num = 0;
int cyc_size = 0;
void addToBegGraph(int A, int B){
if(beg_other_end[A].f == B){
assert(beg_other_end[B].f == A);
cyc_num++;
cyc_size = beg_other_end[A].s;
}
else{
int tot_size = beg_other_end[A].s+beg_other_end[B].s;
int a = beg_other_end[A].f;
int b = beg_other_end[B].f;
beg_other_end[a] = mp(b, tot_size);
beg_other_end[b] = mp(a, tot_size);
}
}
void Init(int _N) {
N = _N;
for(int i = 0; i < N; i++){
beg_other_end[i] = mp(i, 1);
}
}
bool cand_bad[4];
int cand_other_end[4][mx];
void addToCandGraph(int cand_num, int A, int B){ //update cand_bad
if(cand_bad[cand_num]) return;
if(cand_other_end[cand_num][A] == -1 || cand_other_end[cand_num][B] == -1){
cand_bad[cand_num] = 1;
return;
}
if(cand_other_end[cand_num][A] == B){
assert(cand_other_end[cand_num][B] == A);
cand_bad[cand_num] = 1;
return;
}
int a = cand_other_end[cand_num][A];
int b = cand_other_end[cand_num][B];
cand_other_end[cand_num][A] = cand_other_end[cand_num][B] = -1;
cand_other_end[cand_num][a] = b;
cand_other_end[cand_num][b] = a;
}
void Link(int A, int B) {
eds.pb(mp(A, B));
if(max_deg >= 3){
for(int i = 0; i < sz(cands); i++){
if(A != cands[i] && B != cands[i]){
addToCandGraph(i, A, B);
}
}
}
else{
deg[A]++;
deg[B]++;
ckmax(max_deg, max(deg[A], deg[B]));
if(deg[B] == 3){
swap(A, B);
}
if(deg[A] == 3){
//start phase 2
cands.pb(A);
for(auto u: eds){
if(u.s == A) swap(u.f, u.s);
if(u.f == A){
cands.pb(u.s);
}
}
assert(sz(cands) == 4);
for(int i = 0; i < 4; i++){
for(int j = 0; j < N; j++){
cand_other_end[i][j] = j;
}
for(auto u: eds){
if(u.f != cands[i] && u.s != cands[i]){
addToCandGraph(i, u.f, u.s);
}
}
}
}
else{
//continue phase 1
addToBegGraph(A, B);
}
}
}
int CountCritical() {
if(max_deg >= 3){ //phase 2
int ans = 0;
for(int i = 0; i < 4; i++){
if(!cand_bad[i]){
ans++;
}
}
return ans;
}
//phase 1
if(cyc_num == 0){
return N;
}
if(cyc_num == 1){
return cyc_size;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
189 ms |
10732 KB |
Output is correct |
2 |
Correct |
335 ms |
37940 KB |
Output is correct |
3 |
Correct |
287 ms |
47908 KB |
Output is correct |
4 |
Correct |
439 ms |
33460 KB |
Output is correct |
5 |
Correct |
451 ms |
33464 KB |
Output is correct |
6 |
Correct |
450 ms |
32844 KB |
Output is correct |
7 |
Correct |
276 ms |
46996 KB |
Output is correct |
8 |
Correct |
522 ms |
46136 KB |
Output is correct |
9 |
Correct |
582 ms |
49172 KB |
Output is correct |
10 |
Correct |
369 ms |
32328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
612 KB |
Output is correct |
12 |
Correct |
4 ms |
912 KB |
Output is correct |
13 |
Correct |
4 ms |
972 KB |
Output is correct |
14 |
Correct |
3 ms |
844 KB |
Output is correct |
15 |
Correct |
3 ms |
972 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
4 ms |
972 KB |
Output is correct |
18 |
Correct |
4 ms |
1176 KB |
Output is correct |
19 |
Correct |
4 ms |
780 KB |
Output is correct |
20 |
Correct |
4 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
612 KB |
Output is correct |
12 |
Correct |
4 ms |
912 KB |
Output is correct |
13 |
Correct |
4 ms |
972 KB |
Output is correct |
14 |
Correct |
3 ms |
844 KB |
Output is correct |
15 |
Correct |
3 ms |
972 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
4 ms |
972 KB |
Output is correct |
18 |
Correct |
4 ms |
1176 KB |
Output is correct |
19 |
Correct |
4 ms |
780 KB |
Output is correct |
20 |
Correct |
4 ms |
972 KB |
Output is correct |
21 |
Correct |
14 ms |
1760 KB |
Output is correct |
22 |
Correct |
23 ms |
2716 KB |
Output is correct |
23 |
Correct |
28 ms |
3148 KB |
Output is correct |
24 |
Correct |
28 ms |
3912 KB |
Output is correct |
25 |
Correct |
13 ms |
3192 KB |
Output is correct |
26 |
Correct |
28 ms |
4480 KB |
Output is correct |
27 |
Correct |
29 ms |
3576 KB |
Output is correct |
28 |
Correct |
27 ms |
4828 KB |
Output is correct |
29 |
Correct |
26 ms |
4144 KB |
Output is correct |
30 |
Correct |
31 ms |
3472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
189 ms |
10732 KB |
Output is correct |
12 |
Correct |
335 ms |
37940 KB |
Output is correct |
13 |
Correct |
287 ms |
47908 KB |
Output is correct |
14 |
Correct |
439 ms |
33460 KB |
Output is correct |
15 |
Correct |
451 ms |
33464 KB |
Output is correct |
16 |
Correct |
450 ms |
32844 KB |
Output is correct |
17 |
Correct |
276 ms |
46996 KB |
Output is correct |
18 |
Correct |
522 ms |
46136 KB |
Output is correct |
19 |
Correct |
582 ms |
49172 KB |
Output is correct |
20 |
Correct |
369 ms |
32328 KB |
Output is correct |
21 |
Correct |
2 ms |
612 KB |
Output is correct |
22 |
Correct |
4 ms |
912 KB |
Output is correct |
23 |
Correct |
4 ms |
972 KB |
Output is correct |
24 |
Correct |
3 ms |
844 KB |
Output is correct |
25 |
Correct |
3 ms |
972 KB |
Output is correct |
26 |
Correct |
3 ms |
716 KB |
Output is correct |
27 |
Correct |
4 ms |
972 KB |
Output is correct |
28 |
Correct |
4 ms |
1176 KB |
Output is correct |
29 |
Correct |
4 ms |
780 KB |
Output is correct |
30 |
Correct |
4 ms |
972 KB |
Output is correct |
31 |
Correct |
14 ms |
1760 KB |
Output is correct |
32 |
Correct |
23 ms |
2716 KB |
Output is correct |
33 |
Correct |
28 ms |
3148 KB |
Output is correct |
34 |
Correct |
28 ms |
3912 KB |
Output is correct |
35 |
Correct |
13 ms |
3192 KB |
Output is correct |
36 |
Correct |
28 ms |
4480 KB |
Output is correct |
37 |
Correct |
29 ms |
3576 KB |
Output is correct |
38 |
Correct |
27 ms |
4828 KB |
Output is correct |
39 |
Correct |
26 ms |
4144 KB |
Output is correct |
40 |
Correct |
31 ms |
3472 KB |
Output is correct |
41 |
Correct |
157 ms |
13624 KB |
Output is correct |
42 |
Correct |
344 ms |
36064 KB |
Output is correct |
43 |
Correct |
219 ms |
28120 KB |
Output is correct |
44 |
Correct |
285 ms |
44964 KB |
Output is correct |
45 |
Correct |
326 ms |
44628 KB |
Output is correct |
46 |
Correct |
362 ms |
29116 KB |
Output is correct |
47 |
Correct |
405 ms |
29632 KB |
Output is correct |
48 |
Correct |
263 ms |
38580 KB |
Output is correct |
49 |
Correct |
360 ms |
30372 KB |
Output is correct |
50 |
Correct |
377 ms |
29988 KB |
Output is correct |
51 |
Correct |
207 ms |
27712 KB |
Output is correct |
52 |
Correct |
271 ms |
36948 KB |
Output is correct |
53 |
Correct |
233 ms |
37936 KB |
Output is correct |
54 |
Correct |
473 ms |
40960 KB |
Output is correct |
55 |
Correct |
326 ms |
43760 KB |
Output is correct |