#include <bits/stdc++.h>
using namespace std;
const int nx=1e6+5;
int n, dsu[nx], deg[nx], c, sz[nx], cy, res;
vector<int> d[nx];
vector<pair<int, int>> edg;
int find(int x)
{
if (dsu[x]==x) return x;
return dsu[x]=find(dsu[x]);
}
struct universe
{
int rt, pa[nx], ans, deg[nx];
int find(int x)
{
if (pa[x]==x) return x;
return pa[x]=find(pa[x]);
}
void merge(int u, int v)
{
if (u==rt||v==rt||ans==0) return;
if (++deg[u]==3) ans=0;
if (++deg[v]==3) ans=0;
if (find(u)==find(v)) ans=0;
else pa[find(u)]=find(v);
}
void init()
{
ans=1;
for (int i=0; i<n; i++) pa[i]=i;
for (auto x:edg) merge(x.first, x.second);
}
} uni[4];
void Init(int N_) {
n=N_;
for (int i=0; i<n; i++) dsu[i]=i, sz[i]=1;
}
void Link(int A, int B) {
if (c) for (int i=0; i<4; i++) uni[i].merge(A, B);
else
{
edg.push_back({A, B});
d[A].push_back(B);
d[B].push_back(A);
if (deg[A]+1==3||deg[B]+1==3) c=1;
if (++deg[A]==3)
{
uni[0].rt=A;
for (int i=0; i<3; i++) uni[1+i].rt=d[A][i];
for (int i=0; i<4; i++) uni[i].init();
return;
}
if (++deg[B]==3)
{
uni[0].rt=B;
for (int i=0; i<3; i++) uni[1+i].rt=d[B][i];
for (int i=0; i<4; i++) uni[i].init();
return;
}
if (find(A)!=find(B)) sz[find(A)]+=sz[find(B)], dsu[find(B)]=find(A);
else res=sz[find(A)], cy++;
}
}
int CountCritical() {
if (cy>1) return 0;
if (c) return uni[0].ans+uni[1].ans+uni[2].ans+uni[3].ans;
if (cy==1) return res;
return n;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
24120 KB |
Output is correct |
3 |
Correct |
11 ms |
24152 KB |
Output is correct |
4 |
Correct |
11 ms |
23820 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
10 ms |
24252 KB |
Output is correct |
8 |
Correct |
11 ms |
24156 KB |
Output is correct |
9 |
Correct |
11 ms |
24156 KB |
Output is correct |
10 |
Correct |
11 ms |
24412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
212 ms |
50376 KB |
Output is correct |
2 |
Correct |
286 ms |
74424 KB |
Output is correct |
3 |
Correct |
165 ms |
67408 KB |
Output is correct |
4 |
Correct |
592 ms |
74692 KB |
Output is correct |
5 |
Correct |
588 ms |
74516 KB |
Output is correct |
6 |
Correct |
566 ms |
73388 KB |
Output is correct |
7 |
Correct |
140 ms |
67596 KB |
Output is correct |
8 |
Correct |
496 ms |
95332 KB |
Output is correct |
9 |
Correct |
602 ms |
103564 KB |
Output is correct |
10 |
Correct |
428 ms |
72876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
24120 KB |
Output is correct |
3 |
Correct |
11 ms |
24152 KB |
Output is correct |
4 |
Correct |
11 ms |
23820 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
10 ms |
24252 KB |
Output is correct |
8 |
Correct |
11 ms |
24156 KB |
Output is correct |
9 |
Correct |
11 ms |
24156 KB |
Output is correct |
10 |
Correct |
11 ms |
24412 KB |
Output is correct |
11 |
Correct |
11 ms |
24156 KB |
Output is correct |
12 |
Correct |
13 ms |
24732 KB |
Output is correct |
13 |
Correct |
12 ms |
24604 KB |
Output is correct |
14 |
Correct |
12 ms |
24412 KB |
Output is correct |
15 |
Correct |
11 ms |
24668 KB |
Output is correct |
16 |
Correct |
13 ms |
24540 KB |
Output is correct |
17 |
Correct |
12 ms |
24412 KB |
Output is correct |
18 |
Correct |
12 ms |
24964 KB |
Output is correct |
19 |
Correct |
13 ms |
24668 KB |
Output is correct |
20 |
Correct |
13 ms |
24668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
24120 KB |
Output is correct |
3 |
Correct |
11 ms |
24152 KB |
Output is correct |
4 |
Correct |
11 ms |
23820 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
10 ms |
24252 KB |
Output is correct |
8 |
Correct |
11 ms |
24156 KB |
Output is correct |
9 |
Correct |
11 ms |
24156 KB |
Output is correct |
10 |
Correct |
11 ms |
24412 KB |
Output is correct |
11 |
Correct |
11 ms |
24156 KB |
Output is correct |
12 |
Correct |
13 ms |
24732 KB |
Output is correct |
13 |
Correct |
12 ms |
24604 KB |
Output is correct |
14 |
Correct |
12 ms |
24412 KB |
Output is correct |
15 |
Correct |
11 ms |
24668 KB |
Output is correct |
16 |
Correct |
13 ms |
24540 KB |
Output is correct |
17 |
Correct |
12 ms |
24412 KB |
Output is correct |
18 |
Correct |
12 ms |
24964 KB |
Output is correct |
19 |
Correct |
13 ms |
24668 KB |
Output is correct |
20 |
Correct |
13 ms |
24668 KB |
Output is correct |
21 |
Correct |
24 ms |
26092 KB |
Output is correct |
22 |
Correct |
28 ms |
27348 KB |
Output is correct |
23 |
Correct |
35 ms |
28372 KB |
Output is correct |
24 |
Correct |
25 ms |
27416 KB |
Output is correct |
25 |
Correct |
17 ms |
27492 KB |
Output is correct |
26 |
Correct |
27 ms |
28932 KB |
Output is correct |
27 |
Correct |
38 ms |
29132 KB |
Output is correct |
28 |
Correct |
25 ms |
29016 KB |
Output is correct |
29 |
Correct |
25 ms |
29020 KB |
Output is correct |
30 |
Correct |
44 ms |
29892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
24120 KB |
Output is correct |
3 |
Correct |
11 ms |
24152 KB |
Output is correct |
4 |
Correct |
11 ms |
23820 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
11 ms |
24156 KB |
Output is correct |
7 |
Correct |
10 ms |
24252 KB |
Output is correct |
8 |
Correct |
11 ms |
24156 KB |
Output is correct |
9 |
Correct |
11 ms |
24156 KB |
Output is correct |
10 |
Correct |
11 ms |
24412 KB |
Output is correct |
11 |
Correct |
212 ms |
50376 KB |
Output is correct |
12 |
Correct |
286 ms |
74424 KB |
Output is correct |
13 |
Correct |
165 ms |
67408 KB |
Output is correct |
14 |
Correct |
592 ms |
74692 KB |
Output is correct |
15 |
Correct |
588 ms |
74516 KB |
Output is correct |
16 |
Correct |
566 ms |
73388 KB |
Output is correct |
17 |
Correct |
140 ms |
67596 KB |
Output is correct |
18 |
Correct |
496 ms |
95332 KB |
Output is correct |
19 |
Correct |
602 ms |
103564 KB |
Output is correct |
20 |
Correct |
428 ms |
72876 KB |
Output is correct |
21 |
Correct |
11 ms |
24156 KB |
Output is correct |
22 |
Correct |
13 ms |
24732 KB |
Output is correct |
23 |
Correct |
12 ms |
24604 KB |
Output is correct |
24 |
Correct |
12 ms |
24412 KB |
Output is correct |
25 |
Correct |
11 ms |
24668 KB |
Output is correct |
26 |
Correct |
13 ms |
24540 KB |
Output is correct |
27 |
Correct |
12 ms |
24412 KB |
Output is correct |
28 |
Correct |
12 ms |
24964 KB |
Output is correct |
29 |
Correct |
13 ms |
24668 KB |
Output is correct |
30 |
Correct |
13 ms |
24668 KB |
Output is correct |
31 |
Correct |
24 ms |
26092 KB |
Output is correct |
32 |
Correct |
28 ms |
27348 KB |
Output is correct |
33 |
Correct |
35 ms |
28372 KB |
Output is correct |
34 |
Correct |
25 ms |
27416 KB |
Output is correct |
35 |
Correct |
17 ms |
27492 KB |
Output is correct |
36 |
Correct |
27 ms |
28932 KB |
Output is correct |
37 |
Correct |
38 ms |
29132 KB |
Output is correct |
38 |
Correct |
25 ms |
29016 KB |
Output is correct |
39 |
Correct |
25 ms |
29020 KB |
Output is correct |
40 |
Correct |
44 ms |
29892 KB |
Output is correct |
41 |
Correct |
124 ms |
43456 KB |
Output is correct |
42 |
Correct |
250 ms |
81848 KB |
Output is correct |
43 |
Correct |
120 ms |
56056 KB |
Output is correct |
44 |
Correct |
213 ms |
75852 KB |
Output is correct |
45 |
Correct |
188 ms |
78028 KB |
Output is correct |
46 |
Correct |
376 ms |
77844 KB |
Output is correct |
47 |
Correct |
507 ms |
78760 KB |
Output is correct |
48 |
Correct |
148 ms |
75344 KB |
Output is correct |
49 |
Correct |
383 ms |
77152 KB |
Output is correct |
50 |
Correct |
405 ms |
76460 KB |
Output is correct |
51 |
Correct |
121 ms |
61472 KB |
Output is correct |
52 |
Correct |
150 ms |
66552 KB |
Output is correct |
53 |
Correct |
132 ms |
74320 KB |
Output is correct |
54 |
Correct |
395 ms |
92088 KB |
Output is correct |
55 |
Correct |
204 ms |
74464 KB |
Output is correct |