#include <bits/stdc++.h>
using namespace std;
vector<array<int, 2>> g;
int N, p;
struct Solver {
int e[1<<20], d[1<<20] = {};
int maxDeg = 0, cycle = -1, rem = -1;
int find(int u){
return e[u] < 0 ? u : e[u] = find(e[u]);
}
void add(int u, int v) {
if(u == rem || v == rem) return;
maxDeg = max({maxDeg, ++d[u], ++d[v]});
if((u = find(u)) == (v = find(v))) {
cycle = cycle >= 0 ? N : u;
} else {
if(e[u] > e[v]) swap(u, v);
e[u] += e[v], e[v] = u;
}
}
int get() {
if(maxDeg > 2) return 0;
return cycle >= 0 ? e[cycle] : N;
}
} s[5];
void Init(int N_) {
N = N_;
s[0].get();
for(int i = 0; i < 5; i++)
fill(s[i].e, s[i].e+N, -1);
}
void Link(int A, int B) {
g.push_back({A, B});
if(!p) {
s[0].add(A, B);
if(s[0].maxDeg > 2) {
for(int i = 0; i < N; i++)
if(s[0].d[i] > 2) s[p=1].rem = i;
for(auto &[u, v] : g) {
if(u == s[1].rem) s[++p].rem = v;
if(v == s[1].rem) s[++p].rem = u;
}
for(int i = 1; i < 5; i++)
for(auto &[u, v] : g)
s[i].add(u, v);
}
} else {
for(int i = 1; i < 5; i++)
s[i].add(A, B);
}
}
int CountCritical() {
int res = 0;
if(!p) res = abs(s[0].get());
else {
for(int i = 1; i < 5; i++)
res += s[i].get() > 0;
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
20812 KB |
Output is correct |
2 |
Correct |
9 ms |
20940 KB |
Output is correct |
3 |
Correct |
9 ms |
21016 KB |
Output is correct |
4 |
Correct |
8 ms |
20812 KB |
Output is correct |
5 |
Correct |
9 ms |
20940 KB |
Output is correct |
6 |
Correct |
8 ms |
21076 KB |
Output is correct |
7 |
Correct |
8 ms |
20940 KB |
Output is correct |
8 |
Correct |
11 ms |
21068 KB |
Output is correct |
9 |
Correct |
10 ms |
21068 KB |
Output is correct |
10 |
Correct |
9 ms |
21068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
35256 KB |
Output is correct |
2 |
Correct |
518 ms |
44924 KB |
Output is correct |
3 |
Correct |
667 ms |
48700 KB |
Output is correct |
4 |
Correct |
320 ms |
48740 KB |
Output is correct |
5 |
Correct |
310 ms |
48728 KB |
Output is correct |
6 |
Correct |
286 ms |
48628 KB |
Output is correct |
7 |
Correct |
639 ms |
48820 KB |
Output is correct |
8 |
Correct |
588 ms |
47496 KB |
Output is correct |
9 |
Correct |
635 ms |
48688 KB |
Output is correct |
10 |
Correct |
260 ms |
48724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
20812 KB |
Output is correct |
2 |
Correct |
9 ms |
20940 KB |
Output is correct |
3 |
Correct |
9 ms |
21016 KB |
Output is correct |
4 |
Correct |
8 ms |
20812 KB |
Output is correct |
5 |
Correct |
9 ms |
20940 KB |
Output is correct |
6 |
Correct |
8 ms |
21076 KB |
Output is correct |
7 |
Correct |
8 ms |
20940 KB |
Output is correct |
8 |
Correct |
11 ms |
21068 KB |
Output is correct |
9 |
Correct |
10 ms |
21068 KB |
Output is correct |
10 |
Correct |
9 ms |
21068 KB |
Output is correct |
11 |
Correct |
10 ms |
21032 KB |
Output is correct |
12 |
Correct |
11 ms |
21196 KB |
Output is correct |
13 |
Correct |
11 ms |
21308 KB |
Output is correct |
14 |
Correct |
10 ms |
21220 KB |
Output is correct |
15 |
Correct |
11 ms |
21332 KB |
Output is correct |
16 |
Correct |
10 ms |
21308 KB |
Output is correct |
17 |
Correct |
11 ms |
21224 KB |
Output is correct |
18 |
Correct |
14 ms |
21448 KB |
Output is correct |
19 |
Correct |
10 ms |
21240 KB |
Output is correct |
20 |
Correct |
12 ms |
21196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
20812 KB |
Output is correct |
2 |
Correct |
9 ms |
20940 KB |
Output is correct |
3 |
Correct |
9 ms |
21016 KB |
Output is correct |
4 |
Correct |
8 ms |
20812 KB |
Output is correct |
5 |
Correct |
9 ms |
20940 KB |
Output is correct |
6 |
Correct |
8 ms |
21076 KB |
Output is correct |
7 |
Correct |
8 ms |
20940 KB |
Output is correct |
8 |
Correct |
11 ms |
21068 KB |
Output is correct |
9 |
Correct |
10 ms |
21068 KB |
Output is correct |
10 |
Correct |
9 ms |
21068 KB |
Output is correct |
11 |
Correct |
10 ms |
21032 KB |
Output is correct |
12 |
Correct |
11 ms |
21196 KB |
Output is correct |
13 |
Correct |
11 ms |
21308 KB |
Output is correct |
14 |
Correct |
10 ms |
21220 KB |
Output is correct |
15 |
Correct |
11 ms |
21332 KB |
Output is correct |
16 |
Correct |
10 ms |
21308 KB |
Output is correct |
17 |
Correct |
11 ms |
21224 KB |
Output is correct |
18 |
Correct |
14 ms |
21448 KB |
Output is correct |
19 |
Correct |
10 ms |
21240 KB |
Output is correct |
20 |
Correct |
12 ms |
21196 KB |
Output is correct |
21 |
Correct |
18 ms |
22352 KB |
Output is correct |
22 |
Correct |
24 ms |
23296 KB |
Output is correct |
23 |
Correct |
31 ms |
23688 KB |
Output is correct |
24 |
Correct |
36 ms |
23388 KB |
Output is correct |
25 |
Correct |
18 ms |
23100 KB |
Output is correct |
26 |
Correct |
36 ms |
23408 KB |
Output is correct |
27 |
Correct |
29 ms |
23756 KB |
Output is correct |
28 |
Correct |
42 ms |
24828 KB |
Output is correct |
29 |
Correct |
30 ms |
23964 KB |
Output is correct |
30 |
Correct |
32 ms |
25008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
20812 KB |
Output is correct |
2 |
Correct |
9 ms |
20940 KB |
Output is correct |
3 |
Correct |
9 ms |
21016 KB |
Output is correct |
4 |
Correct |
8 ms |
20812 KB |
Output is correct |
5 |
Correct |
9 ms |
20940 KB |
Output is correct |
6 |
Correct |
8 ms |
21076 KB |
Output is correct |
7 |
Correct |
8 ms |
20940 KB |
Output is correct |
8 |
Correct |
11 ms |
21068 KB |
Output is correct |
9 |
Correct |
10 ms |
21068 KB |
Output is correct |
10 |
Correct |
9 ms |
21068 KB |
Output is correct |
11 |
Correct |
138 ms |
35256 KB |
Output is correct |
12 |
Correct |
518 ms |
44924 KB |
Output is correct |
13 |
Correct |
667 ms |
48700 KB |
Output is correct |
14 |
Correct |
320 ms |
48740 KB |
Output is correct |
15 |
Correct |
310 ms |
48728 KB |
Output is correct |
16 |
Correct |
286 ms |
48628 KB |
Output is correct |
17 |
Correct |
639 ms |
48820 KB |
Output is correct |
18 |
Correct |
588 ms |
47496 KB |
Output is correct |
19 |
Correct |
635 ms |
48688 KB |
Output is correct |
20 |
Correct |
260 ms |
48724 KB |
Output is correct |
21 |
Correct |
10 ms |
21032 KB |
Output is correct |
22 |
Correct |
11 ms |
21196 KB |
Output is correct |
23 |
Correct |
11 ms |
21308 KB |
Output is correct |
24 |
Correct |
10 ms |
21220 KB |
Output is correct |
25 |
Correct |
11 ms |
21332 KB |
Output is correct |
26 |
Correct |
10 ms |
21308 KB |
Output is correct |
27 |
Correct |
11 ms |
21224 KB |
Output is correct |
28 |
Correct |
14 ms |
21448 KB |
Output is correct |
29 |
Correct |
10 ms |
21240 KB |
Output is correct |
30 |
Correct |
12 ms |
21196 KB |
Output is correct |
31 |
Correct |
18 ms |
22352 KB |
Output is correct |
32 |
Correct |
24 ms |
23296 KB |
Output is correct |
33 |
Correct |
31 ms |
23688 KB |
Output is correct |
34 |
Correct |
36 ms |
23388 KB |
Output is correct |
35 |
Correct |
18 ms |
23100 KB |
Output is correct |
36 |
Correct |
36 ms |
23408 KB |
Output is correct |
37 |
Correct |
29 ms |
23756 KB |
Output is correct |
38 |
Correct |
42 ms |
24828 KB |
Output is correct |
39 |
Correct |
30 ms |
23964 KB |
Output is correct |
40 |
Correct |
32 ms |
25008 KB |
Output is correct |
41 |
Correct |
120 ms |
38000 KB |
Output is correct |
42 |
Correct |
303 ms |
49828 KB |
Output is correct |
43 |
Correct |
202 ms |
44736 KB |
Output is correct |
44 |
Correct |
442 ms |
58240 KB |
Output is correct |
45 |
Correct |
456 ms |
57288 KB |
Output is correct |
46 |
Correct |
261 ms |
55960 KB |
Output is correct |
47 |
Correct |
293 ms |
56488 KB |
Output is correct |
48 |
Correct |
315 ms |
51388 KB |
Output is correct |
49 |
Correct |
294 ms |
58920 KB |
Output is correct |
50 |
Correct |
284 ms |
58184 KB |
Output is correct |
51 |
Correct |
227 ms |
42576 KB |
Output is correct |
52 |
Correct |
403 ms |
52084 KB |
Output is correct |
53 |
Correct |
312 ms |
50716 KB |
Output is correct |
54 |
Correct |
551 ms |
55108 KB |
Output is correct |
55 |
Correct |
658 ms |
57508 KB |
Output is correct |