#include <bits/stdc++.h>
using namespace std;
array<int, 2> g[1<<20];
int N, p, j;
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 || maxDeg > 2) 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) {
if(!p) {
s[0].add(A, B);
g[j++] = {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(int k = 0; k < j; k++)
for(int i : {0, 1})
if(g[k][i] == s[1].rem) s[++p].rem = g[k][!i];
for(int i = 1; i < 5; i++)
for(int k = 0; k < j; k++)
s[i].add(g[k][0], g[k][1]);
}
} else
for(int i = 1; i < 5; i++)
s[i].add(A, B);
}
int CountCritical() {
int res = 0;
if(p)
for(int i = 1; i < 5; i++)
res += s[i].get() > 0;
else res = abs(s[0].get());
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
20812 KB |
Output is correct |
2 |
Correct |
11 ms |
20916 KB |
Output is correct |
3 |
Correct |
9 ms |
20940 KB |
Output is correct |
4 |
Correct |
9 ms |
20868 KB |
Output is correct |
5 |
Correct |
12 ms |
20956 KB |
Output is correct |
6 |
Correct |
10 ms |
21032 KB |
Output is correct |
7 |
Correct |
9 ms |
20868 KB |
Output is correct |
8 |
Correct |
10 ms |
20924 KB |
Output is correct |
9 |
Correct |
10 ms |
20940 KB |
Output is correct |
10 |
Correct |
9 ms |
21068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
35120 KB |
Output is correct |
2 |
Correct |
323 ms |
39064 KB |
Output is correct |
3 |
Correct |
225 ms |
40816 KB |
Output is correct |
4 |
Correct |
338 ms |
48492 KB |
Output is correct |
5 |
Correct |
349 ms |
48516 KB |
Output is correct |
6 |
Correct |
359 ms |
48048 KB |
Output is correct |
7 |
Correct |
187 ms |
40900 KB |
Output is correct |
8 |
Correct |
542 ms |
44600 KB |
Output is correct |
9 |
Correct |
620 ms |
46844 KB |
Output is correct |
10 |
Correct |
282 ms |
52384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
20812 KB |
Output is correct |
2 |
Correct |
11 ms |
20916 KB |
Output is correct |
3 |
Correct |
9 ms |
20940 KB |
Output is correct |
4 |
Correct |
9 ms |
20868 KB |
Output is correct |
5 |
Correct |
12 ms |
20956 KB |
Output is correct |
6 |
Correct |
10 ms |
21032 KB |
Output is correct |
7 |
Correct |
9 ms |
20868 KB |
Output is correct |
8 |
Correct |
10 ms |
20924 KB |
Output is correct |
9 |
Correct |
10 ms |
20940 KB |
Output is correct |
10 |
Correct |
9 ms |
21068 KB |
Output is correct |
11 |
Correct |
10 ms |
21036 KB |
Output is correct |
12 |
Correct |
12 ms |
21196 KB |
Output is correct |
13 |
Correct |
11 ms |
21192 KB |
Output is correct |
14 |
Correct |
10 ms |
21044 KB |
Output is correct |
15 |
Correct |
10 ms |
21304 KB |
Output is correct |
16 |
Correct |
10 ms |
21196 KB |
Output is correct |
17 |
Correct |
10 ms |
21316 KB |
Output is correct |
18 |
Correct |
11 ms |
21368 KB |
Output is correct |
19 |
Correct |
12 ms |
21208 KB |
Output is correct |
20 |
Correct |
12 ms |
21196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
20812 KB |
Output is correct |
2 |
Correct |
11 ms |
20916 KB |
Output is correct |
3 |
Correct |
9 ms |
20940 KB |
Output is correct |
4 |
Correct |
9 ms |
20868 KB |
Output is correct |
5 |
Correct |
12 ms |
20956 KB |
Output is correct |
6 |
Correct |
10 ms |
21032 KB |
Output is correct |
7 |
Correct |
9 ms |
20868 KB |
Output is correct |
8 |
Correct |
10 ms |
20924 KB |
Output is correct |
9 |
Correct |
10 ms |
20940 KB |
Output is correct |
10 |
Correct |
9 ms |
21068 KB |
Output is correct |
11 |
Correct |
10 ms |
21036 KB |
Output is correct |
12 |
Correct |
12 ms |
21196 KB |
Output is correct |
13 |
Correct |
11 ms |
21192 KB |
Output is correct |
14 |
Correct |
10 ms |
21044 KB |
Output is correct |
15 |
Correct |
10 ms |
21304 KB |
Output is correct |
16 |
Correct |
10 ms |
21196 KB |
Output is correct |
17 |
Correct |
10 ms |
21316 KB |
Output is correct |
18 |
Correct |
11 ms |
21368 KB |
Output is correct |
19 |
Correct |
12 ms |
21208 KB |
Output is correct |
20 |
Correct |
12 ms |
21196 KB |
Output is correct |
21 |
Correct |
20 ms |
22644 KB |
Output is correct |
22 |
Correct |
26 ms |
23680 KB |
Output is correct |
23 |
Correct |
31 ms |
24328 KB |
Output is correct |
24 |
Correct |
32 ms |
23620 KB |
Output is correct |
25 |
Correct |
19 ms |
23116 KB |
Output is correct |
26 |
Correct |
35 ms |
23704 KB |
Output is correct |
27 |
Correct |
29 ms |
24260 KB |
Output is correct |
28 |
Correct |
27 ms |
23680 KB |
Output is correct |
29 |
Correct |
31 ms |
23664 KB |
Output is correct |
30 |
Correct |
30 ms |
24772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
20812 KB |
Output is correct |
2 |
Correct |
11 ms |
20916 KB |
Output is correct |
3 |
Correct |
9 ms |
20940 KB |
Output is correct |
4 |
Correct |
9 ms |
20868 KB |
Output is correct |
5 |
Correct |
12 ms |
20956 KB |
Output is correct |
6 |
Correct |
10 ms |
21032 KB |
Output is correct |
7 |
Correct |
9 ms |
20868 KB |
Output is correct |
8 |
Correct |
10 ms |
20924 KB |
Output is correct |
9 |
Correct |
10 ms |
20940 KB |
Output is correct |
10 |
Correct |
9 ms |
21068 KB |
Output is correct |
11 |
Correct |
131 ms |
35120 KB |
Output is correct |
12 |
Correct |
323 ms |
39064 KB |
Output is correct |
13 |
Correct |
225 ms |
40816 KB |
Output is correct |
14 |
Correct |
338 ms |
48492 KB |
Output is correct |
15 |
Correct |
349 ms |
48516 KB |
Output is correct |
16 |
Correct |
359 ms |
48048 KB |
Output is correct |
17 |
Correct |
187 ms |
40900 KB |
Output is correct |
18 |
Correct |
542 ms |
44600 KB |
Output is correct |
19 |
Correct |
620 ms |
46844 KB |
Output is correct |
20 |
Correct |
282 ms |
52384 KB |
Output is correct |
21 |
Correct |
10 ms |
21036 KB |
Output is correct |
22 |
Correct |
12 ms |
21196 KB |
Output is correct |
23 |
Correct |
11 ms |
21192 KB |
Output is correct |
24 |
Correct |
10 ms |
21044 KB |
Output is correct |
25 |
Correct |
10 ms |
21304 KB |
Output is correct |
26 |
Correct |
10 ms |
21196 KB |
Output is correct |
27 |
Correct |
10 ms |
21316 KB |
Output is correct |
28 |
Correct |
11 ms |
21368 KB |
Output is correct |
29 |
Correct |
12 ms |
21208 KB |
Output is correct |
30 |
Correct |
12 ms |
21196 KB |
Output is correct |
31 |
Correct |
20 ms |
22644 KB |
Output is correct |
32 |
Correct |
26 ms |
23680 KB |
Output is correct |
33 |
Correct |
31 ms |
24328 KB |
Output is correct |
34 |
Correct |
32 ms |
23620 KB |
Output is correct |
35 |
Correct |
19 ms |
23116 KB |
Output is correct |
36 |
Correct |
35 ms |
23704 KB |
Output is correct |
37 |
Correct |
29 ms |
24260 KB |
Output is correct |
38 |
Correct |
27 ms |
23680 KB |
Output is correct |
39 |
Correct |
31 ms |
23664 KB |
Output is correct |
40 |
Correct |
30 ms |
24772 KB |
Output is correct |
41 |
Correct |
122 ms |
37920 KB |
Output is correct |
42 |
Correct |
333 ms |
46584 KB |
Output is correct |
43 |
Correct |
178 ms |
44088 KB |
Output is correct |
44 |
Correct |
242 ms |
43492 KB |
Output is correct |
45 |
Correct |
257 ms |
45764 KB |
Output is correct |
46 |
Correct |
322 ms |
49012 KB |
Output is correct |
47 |
Correct |
320 ms |
49320 KB |
Output is correct |
48 |
Correct |
253 ms |
46604 KB |
Output is correct |
49 |
Correct |
266 ms |
52912 KB |
Output is correct |
50 |
Correct |
296 ms |
52308 KB |
Output is correct |
51 |
Correct |
179 ms |
41468 KB |
Output is correct |
52 |
Correct |
205 ms |
40376 KB |
Output is correct |
53 |
Correct |
177 ms |
45976 KB |
Output is correct |
54 |
Correct |
433 ms |
45104 KB |
Output is correct |
55 |
Correct |
319 ms |
42716 KB |
Output is correct |