#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 11;
int N, M;
int deg[MAXN], a[MAXN], b[MAXN];
vector<int> G[MAXN];
struct DSU{
int dsu[MAXN], sz[MAXN];
void init(int n){
for(int i = 0; i < n; i++) dsu[i] = i, sz[i] = 1;
}
int f(int x){
return x == dsu[x] ? x : dsu[x] = f(dsu[x]);
}
int size(int x){
return sz[f(x)];
}
bool g(int x, int y){
x = f(x), y = f(y); if(x == y) return false;
dsu[x] = y; sz[y] += sz[x]; return true;
}
} dsu;
struct Case{
int v; DSU dsu; bool ok; int deg[MAXN];
void init(int v){
Case::v = v;
ok = true; dsu.init(N);
fill(deg, deg + N, 0);
for(int i = 0; i < M; i++){
if(a[i] == v || b[i] == v) continue;
deg[a[i]]++; deg[b[i]]++;
if(deg[a[i]] >= 3 || deg[b[i]] >= 3)
ok = false;
if(!dsu.g(a[i], b[i]))
ok = false;
}
};
void link(){
int i = M - 1;
if(a[i] == v || b[i] == v) return;
deg[a[i]]++; deg[b[i]]++;
if(deg[a[i]] >= 3 || deg[b[i]] >= 3)
ok = false;
if(!dsu.g(a[i], b[i]))
ok = false;
}
bool isCritical(){
return ok;
}
} cases[4];
int caseCount = 0;
void Init(int N_) {
N = N_; dsu.init(N);
}
bool byCase = false;
int cycleCount = 0, cycleLength = 0;
void Link(int A, int B) {
deg[A]++; deg[B]++; a[M] = A, b[M] = B, M++;
G[A].push_back(B); G[B].push_back(A);
if(byCase){
for(int i = 0; i < caseCount; i++) cases[i].link();
return;
}
int v = -1; if(deg[A] >= 3) v = A; if(deg[B] >= 3) v = B;
if(v == -1){
bool b = dsu.g(A, B);
if(!b) cycleCount++, cycleLength += dsu.size(A);
return;
}
byCase = true;
cases[caseCount++].init(v);
for(auto u : G[v]){
cases[caseCount++].init(u);
}
}
int CountCritical() {
int ans = 0;
if(byCase){
for(int i = 0; i < caseCount; i++) ans += cases[i].isCritical();
}else{
if(cycleCount >= 2) ans = 0;
else if(cycleCount == 1) ans = cycleLength;
else ans = N;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
24324 KB |
Output is correct |
3 |
Correct |
13 ms |
24404 KB |
Output is correct |
4 |
Correct |
12 ms |
23796 KB |
Output is correct |
5 |
Correct |
12 ms |
24020 KB |
Output is correct |
6 |
Correct |
13 ms |
24152 KB |
Output is correct |
7 |
Correct |
13 ms |
24188 KB |
Output is correct |
8 |
Correct |
14 ms |
24092 KB |
Output is correct |
9 |
Correct |
14 ms |
24404 KB |
Output is correct |
10 |
Correct |
15 ms |
24488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
368 ms |
57152 KB |
Output is correct |
2 |
Correct |
910 ms |
112748 KB |
Output is correct |
3 |
Correct |
1455 ms |
129792 KB |
Output is correct |
4 |
Correct |
799 ms |
87976 KB |
Output is correct |
5 |
Correct |
877 ms |
88040 KB |
Output is correct |
6 |
Correct |
804 ms |
86240 KB |
Output is correct |
7 |
Correct |
1420 ms |
128412 KB |
Output is correct |
8 |
Correct |
1002 ms |
127908 KB |
Output is correct |
9 |
Correct |
1027 ms |
134936 KB |
Output is correct |
10 |
Correct |
567 ms |
85732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
24324 KB |
Output is correct |
3 |
Correct |
13 ms |
24404 KB |
Output is correct |
4 |
Correct |
12 ms |
23796 KB |
Output is correct |
5 |
Correct |
12 ms |
24020 KB |
Output is correct |
6 |
Correct |
13 ms |
24152 KB |
Output is correct |
7 |
Correct |
13 ms |
24188 KB |
Output is correct |
8 |
Correct |
14 ms |
24092 KB |
Output is correct |
9 |
Correct |
14 ms |
24404 KB |
Output is correct |
10 |
Correct |
15 ms |
24488 KB |
Output is correct |
11 |
Correct |
16 ms |
24404 KB |
Output is correct |
12 |
Correct |
17 ms |
24944 KB |
Output is correct |
13 |
Correct |
17 ms |
24916 KB |
Output is correct |
14 |
Correct |
15 ms |
24760 KB |
Output is correct |
15 |
Correct |
15 ms |
25368 KB |
Output is correct |
16 |
Correct |
16 ms |
24388 KB |
Output is correct |
17 |
Correct |
17 ms |
25044 KB |
Output is correct |
18 |
Correct |
18 ms |
25704 KB |
Output is correct |
19 |
Correct |
18 ms |
24404 KB |
Output is correct |
20 |
Correct |
16 ms |
25040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
24324 KB |
Output is correct |
3 |
Correct |
13 ms |
24404 KB |
Output is correct |
4 |
Correct |
12 ms |
23796 KB |
Output is correct |
5 |
Correct |
12 ms |
24020 KB |
Output is correct |
6 |
Correct |
13 ms |
24152 KB |
Output is correct |
7 |
Correct |
13 ms |
24188 KB |
Output is correct |
8 |
Correct |
14 ms |
24092 KB |
Output is correct |
9 |
Correct |
14 ms |
24404 KB |
Output is correct |
10 |
Correct |
15 ms |
24488 KB |
Output is correct |
11 |
Correct |
16 ms |
24404 KB |
Output is correct |
12 |
Correct |
17 ms |
24944 KB |
Output is correct |
13 |
Correct |
17 ms |
24916 KB |
Output is correct |
14 |
Correct |
15 ms |
24760 KB |
Output is correct |
15 |
Correct |
15 ms |
25368 KB |
Output is correct |
16 |
Correct |
16 ms |
24388 KB |
Output is correct |
17 |
Correct |
17 ms |
25044 KB |
Output is correct |
18 |
Correct |
18 ms |
25704 KB |
Output is correct |
19 |
Correct |
18 ms |
24404 KB |
Output is correct |
20 |
Correct |
16 ms |
25040 KB |
Output is correct |
21 |
Correct |
25 ms |
25992 KB |
Output is correct |
22 |
Correct |
32 ms |
27288 KB |
Output is correct |
23 |
Correct |
37 ms |
28204 KB |
Output is correct |
24 |
Correct |
52 ms |
32080 KB |
Output is correct |
25 |
Correct |
25 ms |
30292 KB |
Output is correct |
26 |
Correct |
47 ms |
32940 KB |
Output is correct |
27 |
Correct |
42 ms |
29156 KB |
Output is correct |
28 |
Correct |
61 ms |
33520 KB |
Output is correct |
29 |
Correct |
52 ms |
32196 KB |
Output is correct |
30 |
Correct |
47 ms |
30028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
24324 KB |
Output is correct |
3 |
Correct |
13 ms |
24404 KB |
Output is correct |
4 |
Correct |
12 ms |
23796 KB |
Output is correct |
5 |
Correct |
12 ms |
24020 KB |
Output is correct |
6 |
Correct |
13 ms |
24152 KB |
Output is correct |
7 |
Correct |
13 ms |
24188 KB |
Output is correct |
8 |
Correct |
14 ms |
24092 KB |
Output is correct |
9 |
Correct |
14 ms |
24404 KB |
Output is correct |
10 |
Correct |
15 ms |
24488 KB |
Output is correct |
11 |
Correct |
368 ms |
57152 KB |
Output is correct |
12 |
Correct |
910 ms |
112748 KB |
Output is correct |
13 |
Correct |
1455 ms |
129792 KB |
Output is correct |
14 |
Correct |
799 ms |
87976 KB |
Output is correct |
15 |
Correct |
877 ms |
88040 KB |
Output is correct |
16 |
Correct |
804 ms |
86240 KB |
Output is correct |
17 |
Correct |
1420 ms |
128412 KB |
Output is correct |
18 |
Correct |
1002 ms |
127908 KB |
Output is correct |
19 |
Correct |
1027 ms |
134936 KB |
Output is correct |
20 |
Correct |
567 ms |
85732 KB |
Output is correct |
21 |
Correct |
16 ms |
24404 KB |
Output is correct |
22 |
Correct |
17 ms |
24944 KB |
Output is correct |
23 |
Correct |
17 ms |
24916 KB |
Output is correct |
24 |
Correct |
15 ms |
24760 KB |
Output is correct |
25 |
Correct |
15 ms |
25368 KB |
Output is correct |
26 |
Correct |
16 ms |
24388 KB |
Output is correct |
27 |
Correct |
17 ms |
25044 KB |
Output is correct |
28 |
Correct |
18 ms |
25704 KB |
Output is correct |
29 |
Correct |
18 ms |
24404 KB |
Output is correct |
30 |
Correct |
16 ms |
25040 KB |
Output is correct |
31 |
Correct |
25 ms |
25992 KB |
Output is correct |
32 |
Correct |
32 ms |
27288 KB |
Output is correct |
33 |
Correct |
37 ms |
28204 KB |
Output is correct |
34 |
Correct |
52 ms |
32080 KB |
Output is correct |
35 |
Correct |
25 ms |
30292 KB |
Output is correct |
36 |
Correct |
47 ms |
32940 KB |
Output is correct |
37 |
Correct |
42 ms |
29156 KB |
Output is correct |
38 |
Correct |
61 ms |
33520 KB |
Output is correct |
39 |
Correct |
52 ms |
32196 KB |
Output is correct |
40 |
Correct |
47 ms |
30028 KB |
Output is correct |
41 |
Correct |
152 ms |
43340 KB |
Output is correct |
42 |
Correct |
399 ms |
99312 KB |
Output is correct |
43 |
Correct |
242 ms |
85648 KB |
Output is correct |
44 |
Correct |
907 ms |
125180 KB |
Output is correct |
45 |
Correct |
913 ms |
116860 KB |
Output is correct |
46 |
Correct |
558 ms |
77992 KB |
Output is correct |
47 |
Correct |
754 ms |
78860 KB |
Output is correct |
48 |
Correct |
559 ms |
107976 KB |
Output is correct |
49 |
Correct |
514 ms |
77048 KB |
Output is correct |
50 |
Correct |
575 ms |
76540 KB |
Output is correct |
51 |
Correct |
286 ms |
80288 KB |
Output is correct |
52 |
Correct |
770 ms |
105864 KB |
Output is correct |
53 |
Correct |
568 ms |
108404 KB |
Output is correct |
54 |
Correct |
969 ms |
114292 KB |
Output is correct |
55 |
Correct |
1210 ms |
122308 KB |
Output is correct |