#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 42;
struct UF {
bool isChain = true, tree[N];
int par[N], deg[N], diff[N], sz[N], nbCycle = 0, total = 0;
void init(int n) {
for(int i = 0; i < n; i++) {
sz[i] = 1;
par[i] = i;
deg[i] = 0;
diff[i] = -1;
tree[i] = true;
}
}
int F(int i) {
if(par[i] == i)
return i;
return par[i] = F(par[i]);
}
int U(int a, int b) {
deg[a]++;
deg[b]++;
int d = max(deg[a], deg[b]);
if(d > 2)
isChain = false;
a = F(a), b = F(b);
if(a == b) {
if(tree[a]) {
total += sz[a];
nbCycle++;
}
diff[a]++;
isChain = false;
tree[a] = false;
return d;
}
if(sz[b] < sz[a])
swap(a, b);
par[a] = b;
sz[b] += sz[a];
diff[b] += diff[a] + 1;
if(diff[b] != -1)
isChain = false;
return d;
}
};
UF uf[5];
vector<int> adj[N];
int n, maxi = 0, nbCrit, no[5];
void create(int i, int iNot) {
no[i] = iNot;
for(int j = 0; j <= n; j++)
if(j != no[i])
for(int k : adj[j])
if(k != no[i] && j < k)
uf[i].U(j, k);
}
void Init(int N_) {
n = N_;
nbCrit = N_;
for(int i = 0; i < 5; i++)
uf[i].init(N_);
}
void Link(int A, int B) {
adj[A].push_back(B);
adj[B].push_back(A);
int newMax = uf[0].U(A, B);
if(maxi == 3) {
nbCrit = 0;
for(int i = 1; i < 5; i++) {
if(A != no[i] && B != no[i])
uf[i].U(A, B);
if(uf[i].isChain)
nbCrit++;
}
} else {
if(newMax == 3) {
maxi = newMax;
int imax = A;
if(uf[0].deg[A] < uf[0].deg[B])
imax = B;
create(1, imax);
for(int j = 0; j < 3; j++)
create(j + 2, adj[imax][j]);
nbCrit = 0;
for(int i = 1; i < 5; i++)
if(uf[i].isChain)
nbCrit++;
} else {
if(uf[0].nbCycle == 0) {
nbCrit = n;
} else if(uf[0].nbCycle == 1) {
nbCrit = uf[0].total;
} else {
nbCrit = 0;
}
}
}
}
int CountCritical() {
return nbCrit;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23884 KB |
Output is correct |
2 |
Correct |
16 ms |
24488 KB |
Output is correct |
3 |
Correct |
16 ms |
24524 KB |
Output is correct |
4 |
Correct |
14 ms |
24096 KB |
Output is correct |
5 |
Correct |
15 ms |
24304 KB |
Output is correct |
6 |
Correct |
15 ms |
24540 KB |
Output is correct |
7 |
Correct |
14 ms |
24396 KB |
Output is correct |
8 |
Correct |
15 ms |
24464 KB |
Output is correct |
9 |
Correct |
15 ms |
24500 KB |
Output is correct |
10 |
Correct |
16 ms |
24524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
507 ms |
83460 KB |
Output is correct |
2 |
Correct |
2041 ms |
115600 KB |
Output is correct |
3 |
Correct |
2351 ms |
134324 KB |
Output is correct |
4 |
Correct |
1334 ms |
138160 KB |
Output is correct |
5 |
Correct |
1343 ms |
138268 KB |
Output is correct |
6 |
Correct |
1289 ms |
136748 KB |
Output is correct |
7 |
Correct |
2298 ms |
133680 KB |
Output is correct |
8 |
Correct |
2377 ms |
131048 KB |
Output is correct |
9 |
Correct |
2453 ms |
138244 KB |
Output is correct |
10 |
Correct |
905 ms |
136464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23884 KB |
Output is correct |
2 |
Correct |
16 ms |
24488 KB |
Output is correct |
3 |
Correct |
16 ms |
24524 KB |
Output is correct |
4 |
Correct |
14 ms |
24096 KB |
Output is correct |
5 |
Correct |
15 ms |
24304 KB |
Output is correct |
6 |
Correct |
15 ms |
24540 KB |
Output is correct |
7 |
Correct |
14 ms |
24396 KB |
Output is correct |
8 |
Correct |
15 ms |
24464 KB |
Output is correct |
9 |
Correct |
15 ms |
24500 KB |
Output is correct |
10 |
Correct |
16 ms |
24524 KB |
Output is correct |
11 |
Correct |
17 ms |
24524 KB |
Output is correct |
12 |
Correct |
20 ms |
25292 KB |
Output is correct |
13 |
Correct |
20 ms |
25156 KB |
Output is correct |
14 |
Correct |
19 ms |
25036 KB |
Output is correct |
15 |
Correct |
18 ms |
25876 KB |
Output is correct |
16 |
Correct |
22 ms |
25152 KB |
Output is correct |
17 |
Correct |
20 ms |
25164 KB |
Output is correct |
18 |
Correct |
21 ms |
26172 KB |
Output is correct |
19 |
Correct |
18 ms |
25200 KB |
Output is correct |
20 |
Correct |
20 ms |
25164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23884 KB |
Output is correct |
2 |
Correct |
16 ms |
24488 KB |
Output is correct |
3 |
Correct |
16 ms |
24524 KB |
Output is correct |
4 |
Correct |
14 ms |
24096 KB |
Output is correct |
5 |
Correct |
15 ms |
24304 KB |
Output is correct |
6 |
Correct |
15 ms |
24540 KB |
Output is correct |
7 |
Correct |
14 ms |
24396 KB |
Output is correct |
8 |
Correct |
15 ms |
24464 KB |
Output is correct |
9 |
Correct |
15 ms |
24500 KB |
Output is correct |
10 |
Correct |
16 ms |
24524 KB |
Output is correct |
11 |
Correct |
17 ms |
24524 KB |
Output is correct |
12 |
Correct |
20 ms |
25292 KB |
Output is correct |
13 |
Correct |
20 ms |
25156 KB |
Output is correct |
14 |
Correct |
19 ms |
25036 KB |
Output is correct |
15 |
Correct |
18 ms |
25876 KB |
Output is correct |
16 |
Correct |
22 ms |
25152 KB |
Output is correct |
17 |
Correct |
20 ms |
25164 KB |
Output is correct |
18 |
Correct |
21 ms |
26172 KB |
Output is correct |
19 |
Correct |
18 ms |
25200 KB |
Output is correct |
20 |
Correct |
20 ms |
25164 KB |
Output is correct |
21 |
Correct |
33 ms |
29556 KB |
Output is correct |
22 |
Correct |
55 ms |
32752 KB |
Output is correct |
23 |
Correct |
62 ms |
35104 KB |
Output is correct |
24 |
Correct |
95 ms |
33988 KB |
Output is correct |
25 |
Correct |
40 ms |
32736 KB |
Output is correct |
26 |
Correct |
102 ms |
34808 KB |
Output is correct |
27 |
Correct |
65 ms |
34628 KB |
Output is correct |
28 |
Correct |
122 ms |
35164 KB |
Output is correct |
29 |
Correct |
77 ms |
34500 KB |
Output is correct |
30 |
Correct |
73 ms |
36420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23884 KB |
Output is correct |
2 |
Correct |
16 ms |
24488 KB |
Output is correct |
3 |
Correct |
16 ms |
24524 KB |
Output is correct |
4 |
Correct |
14 ms |
24096 KB |
Output is correct |
5 |
Correct |
15 ms |
24304 KB |
Output is correct |
6 |
Correct |
15 ms |
24540 KB |
Output is correct |
7 |
Correct |
14 ms |
24396 KB |
Output is correct |
8 |
Correct |
15 ms |
24464 KB |
Output is correct |
9 |
Correct |
15 ms |
24500 KB |
Output is correct |
10 |
Correct |
16 ms |
24524 KB |
Output is correct |
11 |
Correct |
507 ms |
83460 KB |
Output is correct |
12 |
Correct |
2041 ms |
115600 KB |
Output is correct |
13 |
Correct |
2351 ms |
134324 KB |
Output is correct |
14 |
Correct |
1334 ms |
138160 KB |
Output is correct |
15 |
Correct |
1343 ms |
138268 KB |
Output is correct |
16 |
Correct |
1289 ms |
136748 KB |
Output is correct |
17 |
Correct |
2298 ms |
133680 KB |
Output is correct |
18 |
Correct |
2377 ms |
131048 KB |
Output is correct |
19 |
Correct |
2453 ms |
138244 KB |
Output is correct |
20 |
Correct |
905 ms |
136464 KB |
Output is correct |
21 |
Correct |
17 ms |
24524 KB |
Output is correct |
22 |
Correct |
20 ms |
25292 KB |
Output is correct |
23 |
Correct |
20 ms |
25156 KB |
Output is correct |
24 |
Correct |
19 ms |
25036 KB |
Output is correct |
25 |
Correct |
18 ms |
25876 KB |
Output is correct |
26 |
Correct |
22 ms |
25152 KB |
Output is correct |
27 |
Correct |
20 ms |
25164 KB |
Output is correct |
28 |
Correct |
21 ms |
26172 KB |
Output is correct |
29 |
Correct |
18 ms |
25200 KB |
Output is correct |
30 |
Correct |
20 ms |
25164 KB |
Output is correct |
31 |
Correct |
33 ms |
29556 KB |
Output is correct |
32 |
Correct |
55 ms |
32752 KB |
Output is correct |
33 |
Correct |
62 ms |
35104 KB |
Output is correct |
34 |
Correct |
95 ms |
33988 KB |
Output is correct |
35 |
Correct |
40 ms |
32736 KB |
Output is correct |
36 |
Correct |
102 ms |
34808 KB |
Output is correct |
37 |
Correct |
65 ms |
34628 KB |
Output is correct |
38 |
Correct |
122 ms |
35164 KB |
Output is correct |
39 |
Correct |
77 ms |
34500 KB |
Output is correct |
40 |
Correct |
73 ms |
36420 KB |
Output is correct |
41 |
Correct |
275 ms |
77620 KB |
Output is correct |
42 |
Correct |
1033 ms |
116380 KB |
Output is correct |
43 |
Correct |
373 ms |
107776 KB |
Output is correct |
44 |
Correct |
1640 ms |
138912 KB |
Output is correct |
45 |
Correct |
1548 ms |
136356 KB |
Output is correct |
46 |
Correct |
871 ms |
128348 KB |
Output is correct |
47 |
Correct |
1136 ms |
130144 KB |
Output is correct |
48 |
Correct |
982 ms |
129848 KB |
Output is correct |
49 |
Correct |
836 ms |
142660 KB |
Output is correct |
50 |
Correct |
887 ms |
141012 KB |
Output is correct |
51 |
Correct |
497 ms |
98556 KB |
Output is correct |
52 |
Correct |
1395 ms |
117972 KB |
Output is correct |
53 |
Correct |
1004 ms |
130144 KB |
Output is correct |
54 |
Correct |
2082 ms |
126400 KB |
Output is correct |
55 |
Correct |
2286 ms |
134920 KB |
Output is correct |