#include<bits/stdc++.h>
using namespace std;
int N;
vector<int> edg[1000005];
int DEG3 = -1;
int DEG4 = -1;
bool choicesToggle = false;
set<int> choices, tmp;
int dsu[1000005];
int cyc[1000005];
bool vis[1000005];
int pre[1000005];
int cyccnt = 0;
int GG = 0;
vector<int> undolist;
int find(int x) {
if(dsu[x]==x)return x;
return dsu[x] = find(dsu[x]);
}
void setintersection(set<int> tmp) {
if(!choicesToggle) {
choicesToggle = true;
choices = tmp;
return;
}
set<int> tmp2;
for(int i:tmp) {
if(choices.find(i)!=choices.end()) {
tmp2.insert(i);
}
}
choices = tmp2;
}
void dfs(int x, int p, int tar) {
vis[x] = true;
pre[x] = p;
undolist.push_back(x);
if(x==tar) {
int ptr = pre[tar];
tmp.clear();
tmp.insert(tar);
while(ptr != tar) {
tmp.insert(ptr);
ptr = pre[ptr];
}
setintersection(tmp);
return;
}
for(int i:edg[x]) {
if(i==p) continue;
if(!vis[i]) dfs(i, x, tar);
}
}
void merge(int x, int y) {
if(find(x)==find(y)) {
cyc[find(x)]++;
if(cyc[find(x)]<=3) dfs(x, y, y);
for(int i:undolist) vis[i] = false;
undolist.clear();
if(cyc[find(x)]==2) {
tmp.clear();
for(int i:choices) {
if(edg[i].size()>=3) tmp.insert(i);
}
choices = tmp;
}
} else {
cyc[find(x)] += cyc[find(y)];
dsu[find(y)] = find(x);
}
}
void Init(int N_) {
N = N_;
for(int i=0; i<N; i++) dsu[i] = i;
}
void Link(int A, int B) {
if(GG) return;
edg[A].push_back(B);
edg[B].push_back(A);
merge(A, B);
if(edg[A].size()==4) setintersection({A});
else if(edg[A].size()==3) setintersection({A, edg[A][0], edg[A][1], edg[A][2]});
if(edg[B].size()==4) setintersection({B});
else if(edg[B].size()==3) setintersection({B, edg[B][0], edg[B][1], edg[B][2]});
}
int CountCritical() {
if(GG) return 0;
if(!choicesToggle) return N;
else return choices.size();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23760 KB |
Output is correct |
2 |
Correct |
14 ms |
24008 KB |
Output is correct |
3 |
Correct |
15 ms |
24000 KB |
Output is correct |
4 |
Correct |
17 ms |
23796 KB |
Output is correct |
5 |
Correct |
16 ms |
24404 KB |
Output is correct |
6 |
Correct |
16 ms |
25172 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
24148 KB |
Output is correct |
9 |
Correct |
14 ms |
24020 KB |
Output is correct |
10 |
Correct |
14 ms |
23964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
383 ms |
44512 KB |
Output is correct |
2 |
Correct |
774 ms |
55456 KB |
Output is correct |
3 |
Correct |
1080 ms |
64640 KB |
Output is correct |
4 |
Correct |
995 ms |
65900 KB |
Output is correct |
5 |
Correct |
960 ms |
74160 KB |
Output is correct |
6 |
Correct |
1612 ms |
213540 KB |
Output is correct |
7 |
Correct |
999 ms |
63620 KB |
Output is correct |
8 |
Correct |
879 ms |
60424 KB |
Output is correct |
9 |
Correct |
969 ms |
62880 KB |
Output is correct |
10 |
Correct |
1328 ms |
86640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23760 KB |
Output is correct |
2 |
Correct |
14 ms |
24008 KB |
Output is correct |
3 |
Correct |
15 ms |
24000 KB |
Output is correct |
4 |
Correct |
17 ms |
23796 KB |
Output is correct |
5 |
Correct |
16 ms |
24404 KB |
Output is correct |
6 |
Correct |
16 ms |
25172 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
24148 KB |
Output is correct |
9 |
Correct |
14 ms |
24020 KB |
Output is correct |
10 |
Correct |
14 ms |
23964 KB |
Output is correct |
11 |
Correct |
16 ms |
24020 KB |
Output is correct |
12 |
Correct |
17 ms |
24532 KB |
Output is correct |
13 |
Correct |
17 ms |
24520 KB |
Output is correct |
14 |
Correct |
15 ms |
24172 KB |
Output is correct |
15 |
Correct |
16 ms |
24208 KB |
Output is correct |
16 |
Correct |
18 ms |
24396 KB |
Output is correct |
17 |
Correct |
16 ms |
24176 KB |
Output is correct |
18 |
Correct |
17 ms |
24404 KB |
Output is correct |
19 |
Correct |
19 ms |
24404 KB |
Output is correct |
20 |
Correct |
20 ms |
24148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23760 KB |
Output is correct |
2 |
Correct |
14 ms |
24008 KB |
Output is correct |
3 |
Correct |
15 ms |
24000 KB |
Output is correct |
4 |
Correct |
17 ms |
23796 KB |
Output is correct |
5 |
Correct |
16 ms |
24404 KB |
Output is correct |
6 |
Correct |
16 ms |
25172 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
24148 KB |
Output is correct |
9 |
Correct |
14 ms |
24020 KB |
Output is correct |
10 |
Correct |
14 ms |
23964 KB |
Output is correct |
11 |
Correct |
16 ms |
24020 KB |
Output is correct |
12 |
Correct |
17 ms |
24532 KB |
Output is correct |
13 |
Correct |
17 ms |
24520 KB |
Output is correct |
14 |
Correct |
15 ms |
24172 KB |
Output is correct |
15 |
Correct |
16 ms |
24208 KB |
Output is correct |
16 |
Correct |
18 ms |
24396 KB |
Output is correct |
17 |
Correct |
16 ms |
24176 KB |
Output is correct |
18 |
Correct |
17 ms |
24404 KB |
Output is correct |
19 |
Correct |
19 ms |
24404 KB |
Output is correct |
20 |
Correct |
20 ms |
24148 KB |
Output is correct |
21 |
Correct |
28 ms |
25236 KB |
Output is correct |
22 |
Correct |
37 ms |
26012 KB |
Output is correct |
23 |
Correct |
42 ms |
26688 KB |
Output is correct |
24 |
Correct |
46 ms |
26520 KB |
Output is correct |
25 |
Correct |
24 ms |
25204 KB |
Output is correct |
26 |
Correct |
45 ms |
28520 KB |
Output is correct |
27 |
Correct |
73 ms |
28636 KB |
Output is correct |
28 |
Correct |
72 ms |
28640 KB |
Output is correct |
29 |
Correct |
40 ms |
26720 KB |
Output is correct |
30 |
Correct |
73 ms |
32916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23760 KB |
Output is correct |
2 |
Correct |
14 ms |
24008 KB |
Output is correct |
3 |
Correct |
15 ms |
24000 KB |
Output is correct |
4 |
Correct |
17 ms |
23796 KB |
Output is correct |
5 |
Correct |
16 ms |
24404 KB |
Output is correct |
6 |
Correct |
16 ms |
25172 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
24148 KB |
Output is correct |
9 |
Correct |
14 ms |
24020 KB |
Output is correct |
10 |
Correct |
14 ms |
23964 KB |
Output is correct |
11 |
Correct |
383 ms |
44512 KB |
Output is correct |
12 |
Correct |
774 ms |
55456 KB |
Output is correct |
13 |
Correct |
1080 ms |
64640 KB |
Output is correct |
14 |
Correct |
995 ms |
65900 KB |
Output is correct |
15 |
Correct |
960 ms |
74160 KB |
Output is correct |
16 |
Correct |
1612 ms |
213540 KB |
Output is correct |
17 |
Correct |
999 ms |
63620 KB |
Output is correct |
18 |
Correct |
879 ms |
60424 KB |
Output is correct |
19 |
Correct |
969 ms |
62880 KB |
Output is correct |
20 |
Correct |
1328 ms |
86640 KB |
Output is correct |
21 |
Correct |
16 ms |
24020 KB |
Output is correct |
22 |
Correct |
17 ms |
24532 KB |
Output is correct |
23 |
Correct |
17 ms |
24520 KB |
Output is correct |
24 |
Correct |
15 ms |
24172 KB |
Output is correct |
25 |
Correct |
16 ms |
24208 KB |
Output is correct |
26 |
Correct |
18 ms |
24396 KB |
Output is correct |
27 |
Correct |
16 ms |
24176 KB |
Output is correct |
28 |
Correct |
17 ms |
24404 KB |
Output is correct |
29 |
Correct |
19 ms |
24404 KB |
Output is correct |
30 |
Correct |
20 ms |
24148 KB |
Output is correct |
31 |
Correct |
28 ms |
25236 KB |
Output is correct |
32 |
Correct |
37 ms |
26012 KB |
Output is correct |
33 |
Correct |
42 ms |
26688 KB |
Output is correct |
34 |
Correct |
46 ms |
26520 KB |
Output is correct |
35 |
Correct |
24 ms |
25204 KB |
Output is correct |
36 |
Correct |
45 ms |
28520 KB |
Output is correct |
37 |
Correct |
73 ms |
28636 KB |
Output is correct |
38 |
Correct |
72 ms |
28640 KB |
Output is correct |
39 |
Correct |
40 ms |
26720 KB |
Output is correct |
40 |
Correct |
73 ms |
32916 KB |
Output is correct |
41 |
Correct |
207 ms |
39816 KB |
Output is correct |
42 |
Correct |
381 ms |
53428 KB |
Output is correct |
43 |
Correct |
218 ms |
41792 KB |
Output is correct |
44 |
Correct |
626 ms |
75692 KB |
Output is correct |
45 |
Correct |
833 ms |
77924 KB |
Output is correct |
46 |
Correct |
988 ms |
73036 KB |
Output is correct |
47 |
Correct |
1115 ms |
160168 KB |
Output is correct |
48 |
Correct |
419 ms |
54476 KB |
Output is correct |
49 |
Correct |
600 ms |
67596 KB |
Output is correct |
50 |
Correct |
652 ms |
67156 KB |
Output is correct |
51 |
Correct |
246 ms |
42492 KB |
Output is correct |
52 |
Correct |
520 ms |
66468 KB |
Output is correct |
53 |
Correct |
457 ms |
54764 KB |
Output is correct |
54 |
Correct |
805 ms |
67332 KB |
Output is correct |
55 |
Correct |
875 ms |
70588 KB |
Output is correct |