// 19.44
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 1000111
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
bool is_end;
struct DSU{
bool over;
int n, owner, max_degree, type;
set<int> cycles;
int deg[maxn];
int sz[maxn];
int root[maxn];
int rooting(int x){
if(root[x] == x)
return x;
return root[x] = rooting(root[x]);
}
void addEdge(int a, int b){
if(a == owner || b == owner || over == 1)
return;
int ra = rooting(a);
int rb = rooting(b);
deg[a]++; deg[a] = min(deg[a], 3);
deg[b]++; deg[b] = min(deg[b], 3);
max_degree = max(max_degree, max(deg[a], deg[b]));
if(ra != rb){
root[rb] = ra;
sz[ra] += sz[rb];
}
if(ra == rb)
cycles.insert(ra);
if(max_degree == 3 || cycles.size() > 1){
over = 1;
if(type == 4)
is_end = 1;
}
if(type >= 3 && cycles.size() == 1){
over = 1;
if(type == 4)
is_end = 1;
}
}
void init(int nn, int x, int t, vector<pii> &edge){
n = nn;
owner = x;
max_degree = over = 0;
type = t;
for(int i = 0; i < maxn; i++){
root[i] = i;
deg[i] = 0;
sz[i] = 1;
}
for(pii v : edge)
addEdge(v.fi, v.se);
}
int getAns(){
if(over)
return 0;
if(type == 2){
if(max_degree <= 1)
return n;
if(max_degree == 2){
if(cycles.size() == 0)
return n;
if(cycles.size() == 1)
return sz[*cycles.begin()];
}
}
if(type == 3 || type == 4)
return 1;
}
} dsu[6];
bool start[6];
int deg[maxn], num[5], ind[5], n;
vector<pii> edge;
vector<int> adj[maxn];
pii cur_range;
int all_max_degree;
void Init(int N){
n = N;
is_end = 0;
all_max_degree = 0;
dsu[0].init(n, -1, 2, edge);
memset(ind, -1, sizeof(ind));
num[0] = n;
start[0] = 1;
cur_range = mp(0, 0);
}
void Link(int A, int B){
if(is_end)
return;
adj[A].pb(B);
adj[B].pb(A);
num[deg[A]]--;
deg[A]++; deg[A] = min(deg[A], 4);
num[deg[A]]++;
if(ind[deg[A]] == -1)
ind[deg[A]] = A;
num[deg[B]]--;
deg[B]++; deg[B] = min(deg[B], 4);
num[deg[B]]++;
if(ind[deg[B]] == -1)
ind[deg[B]] = B;
all_max_degree = max(all_max_degree, max(deg[A], deg[B]));
if(all_max_degree == 3 && !start[1]){
cur_range = mp(1, 4);
start[1] = 1;
int cnt = 1;
dsu[cnt++].init(n, ind[3], 3, edge);
for(int v : adj[ind[3]])
dsu[cnt++].init(n, v, 3, edge);
}
if(all_max_degree == 4 && !start[5]){
cur_range = mp(5, 5);
start[5] = 1;
dsu[5].init(n, ind[4], 4, edge);
}
edge.pb(mp(A, B));
for(int i = cur_range.fi; i <= cur_range.se; i++)
dsu[i].addEdge(A, B);
}
int CountCritical(){
int ret = 0;
for(int i = cur_range.fi; i <= cur_range.se; i++)
ret += dsu[i].getAns();
return ret;
}
Compilation message
rings.cpp: In member function 'int DSU::getAns()':
rings.cpp:101:2: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
35576 KB |
Output is correct |
2 |
Correct |
86 ms |
94588 KB |
Output is correct |
3 |
Correct |
86 ms |
94660 KB |
Output is correct |
4 |
Correct |
33 ms |
94660 KB |
Output is correct |
5 |
Correct |
38 ms |
94660 KB |
Output is correct |
6 |
Correct |
46 ms |
94660 KB |
Output is correct |
7 |
Correct |
83 ms |
94660 KB |
Output is correct |
8 |
Correct |
36 ms |
94660 KB |
Output is correct |
9 |
Correct |
97 ms |
94660 KB |
Output is correct |
10 |
Correct |
91 ms |
94660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
629 ms |
94660 KB |
Output is correct |
2 |
Correct |
1793 ms |
129040 KB |
Output is correct |
3 |
Correct |
438 ms |
129040 KB |
Output is correct |
4 |
Correct |
1827 ms |
129040 KB |
Output is correct |
5 |
Correct |
1746 ms |
129040 KB |
Output is correct |
6 |
Correct |
1683 ms |
129040 KB |
Output is correct |
7 |
Correct |
382 ms |
129040 KB |
Output is correct |
8 |
Correct |
2348 ms |
129040 KB |
Output is correct |
9 |
Correct |
2576 ms |
129040 KB |
Output is correct |
10 |
Correct |
1138 ms |
129040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
35576 KB |
Output is correct |
2 |
Correct |
86 ms |
94588 KB |
Output is correct |
3 |
Correct |
86 ms |
94660 KB |
Output is correct |
4 |
Correct |
33 ms |
94660 KB |
Output is correct |
5 |
Correct |
38 ms |
94660 KB |
Output is correct |
6 |
Correct |
46 ms |
94660 KB |
Output is correct |
7 |
Correct |
83 ms |
94660 KB |
Output is correct |
8 |
Correct |
36 ms |
94660 KB |
Output is correct |
9 |
Correct |
97 ms |
94660 KB |
Output is correct |
10 |
Correct |
91 ms |
94660 KB |
Output is correct |
11 |
Correct |
84 ms |
129040 KB |
Output is correct |
12 |
Correct |
89 ms |
129040 KB |
Output is correct |
13 |
Correct |
91 ms |
129040 KB |
Output is correct |
14 |
Correct |
87 ms |
129040 KB |
Output is correct |
15 |
Correct |
86 ms |
129040 KB |
Output is correct |
16 |
Correct |
42 ms |
129040 KB |
Output is correct |
17 |
Correct |
78 ms |
129040 KB |
Output is correct |
18 |
Correct |
88 ms |
129040 KB |
Output is correct |
19 |
Correct |
48 ms |
129040 KB |
Output is correct |
20 |
Correct |
79 ms |
129040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
35576 KB |
Output is correct |
2 |
Correct |
86 ms |
94588 KB |
Output is correct |
3 |
Correct |
86 ms |
94660 KB |
Output is correct |
4 |
Correct |
33 ms |
94660 KB |
Output is correct |
5 |
Correct |
38 ms |
94660 KB |
Output is correct |
6 |
Correct |
46 ms |
94660 KB |
Output is correct |
7 |
Correct |
83 ms |
94660 KB |
Output is correct |
8 |
Correct |
36 ms |
94660 KB |
Output is correct |
9 |
Correct |
97 ms |
94660 KB |
Output is correct |
10 |
Correct |
91 ms |
94660 KB |
Output is correct |
11 |
Correct |
84 ms |
129040 KB |
Output is correct |
12 |
Correct |
89 ms |
129040 KB |
Output is correct |
13 |
Correct |
91 ms |
129040 KB |
Output is correct |
14 |
Correct |
87 ms |
129040 KB |
Output is correct |
15 |
Correct |
86 ms |
129040 KB |
Output is correct |
16 |
Correct |
42 ms |
129040 KB |
Output is correct |
17 |
Correct |
78 ms |
129040 KB |
Output is correct |
18 |
Correct |
88 ms |
129040 KB |
Output is correct |
19 |
Correct |
48 ms |
129040 KB |
Output is correct |
20 |
Correct |
79 ms |
129040 KB |
Output is correct |
21 |
Correct |
57 ms |
129040 KB |
Output is correct |
22 |
Correct |
77 ms |
129040 KB |
Output is correct |
23 |
Correct |
87 ms |
129040 KB |
Output is correct |
24 |
Correct |
143 ms |
129040 KB |
Output is correct |
25 |
Correct |
99 ms |
129040 KB |
Output is correct |
26 |
Correct |
136 ms |
129040 KB |
Output is correct |
27 |
Correct |
97 ms |
129040 KB |
Output is correct |
28 |
Correct |
139 ms |
129040 KB |
Output is correct |
29 |
Correct |
109 ms |
129040 KB |
Output is correct |
30 |
Correct |
143 ms |
129040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
35576 KB |
Output is correct |
2 |
Correct |
86 ms |
94588 KB |
Output is correct |
3 |
Correct |
86 ms |
94660 KB |
Output is correct |
4 |
Correct |
33 ms |
94660 KB |
Output is correct |
5 |
Correct |
38 ms |
94660 KB |
Output is correct |
6 |
Correct |
46 ms |
94660 KB |
Output is correct |
7 |
Correct |
83 ms |
94660 KB |
Output is correct |
8 |
Correct |
36 ms |
94660 KB |
Output is correct |
9 |
Correct |
97 ms |
94660 KB |
Output is correct |
10 |
Correct |
91 ms |
94660 KB |
Output is correct |
11 |
Correct |
629 ms |
94660 KB |
Output is correct |
12 |
Correct |
1793 ms |
129040 KB |
Output is correct |
13 |
Correct |
438 ms |
129040 KB |
Output is correct |
14 |
Correct |
1827 ms |
129040 KB |
Output is correct |
15 |
Correct |
1746 ms |
129040 KB |
Output is correct |
16 |
Correct |
1683 ms |
129040 KB |
Output is correct |
17 |
Correct |
382 ms |
129040 KB |
Output is correct |
18 |
Correct |
2348 ms |
129040 KB |
Output is correct |
19 |
Correct |
2576 ms |
129040 KB |
Output is correct |
20 |
Correct |
1138 ms |
129040 KB |
Output is correct |
21 |
Correct |
84 ms |
129040 KB |
Output is correct |
22 |
Correct |
89 ms |
129040 KB |
Output is correct |
23 |
Correct |
91 ms |
129040 KB |
Output is correct |
24 |
Correct |
87 ms |
129040 KB |
Output is correct |
25 |
Correct |
86 ms |
129040 KB |
Output is correct |
26 |
Correct |
42 ms |
129040 KB |
Output is correct |
27 |
Correct |
78 ms |
129040 KB |
Output is correct |
28 |
Correct |
88 ms |
129040 KB |
Output is correct |
29 |
Correct |
48 ms |
129040 KB |
Output is correct |
30 |
Correct |
79 ms |
129040 KB |
Output is correct |
31 |
Correct |
57 ms |
129040 KB |
Output is correct |
32 |
Correct |
77 ms |
129040 KB |
Output is correct |
33 |
Correct |
87 ms |
129040 KB |
Output is correct |
34 |
Correct |
143 ms |
129040 KB |
Output is correct |
35 |
Correct |
99 ms |
129040 KB |
Output is correct |
36 |
Correct |
136 ms |
129040 KB |
Output is correct |
37 |
Correct |
97 ms |
129040 KB |
Output is correct |
38 |
Correct |
139 ms |
129040 KB |
Output is correct |
39 |
Correct |
109 ms |
129040 KB |
Output is correct |
40 |
Correct |
143 ms |
129040 KB |
Output is correct |
41 |
Correct |
322 ms |
129040 KB |
Output is correct |
42 |
Correct |
1034 ms |
129040 KB |
Output is correct |
43 |
Correct |
379 ms |
129040 KB |
Output is correct |
44 |
Correct |
392 ms |
129040 KB |
Output is correct |
45 |
Correct |
752 ms |
129040 KB |
Output is correct |
46 |
Correct |
1064 ms |
129040 KB |
Output is correct |
47 |
Correct |
1406 ms |
129040 KB |
Output is correct |
48 |
Correct |
365 ms |
129040 KB |
Output is correct |
49 |
Correct |
1073 ms |
129040 KB |
Output is correct |
50 |
Correct |
1111 ms |
129040 KB |
Output is correct |
51 |
Correct |
422 ms |
129040 KB |
Output is correct |
52 |
Correct |
745 ms |
129040 KB |
Output is correct |
53 |
Correct |
331 ms |
129040 KB |
Output is correct |
54 |
Correct |
1976 ms |
129040 KB |
Output is correct |
55 |
Correct |
1643 ms |
132828 KB |
Output is correct |