// 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;
cycles.clear();
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[4];
bool start[6];
int deg[maxn], 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));
start[2] = 1;
cur_range = mp(0, 0);
}
void Link(int A, int B){
if(is_end)
return;
adj[A].pb(B);
adj[B].pb(A);
deg[A]++; deg[A] = min(deg[A], 4);
if(ind[deg[A]] == -1)
ind[deg[A]] = A;
deg[B]++; deg[B] = min(deg[B], 4);
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[3]){
start[3] = 1;
cur_range = mp(0, 3);
int cnt = 0;
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[4]){
start[4] = 1;
cur_range = mp(0, 0);
dsu[0].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:102:2: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
35576 KB |
Output is correct |
2 |
Correct |
71 ms |
71104 KB |
Output is correct |
3 |
Correct |
74 ms |
71104 KB |
Output is correct |
4 |
Correct |
33 ms |
71104 KB |
Output is correct |
5 |
Correct |
33 ms |
71104 KB |
Output is correct |
6 |
Correct |
34 ms |
71104 KB |
Output is correct |
7 |
Correct |
66 ms |
71104 KB |
Output is correct |
8 |
Correct |
34 ms |
71104 KB |
Output is correct |
9 |
Correct |
70 ms |
71236 KB |
Output is correct |
10 |
Correct |
73 ms |
71236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
563 ms |
71236 KB |
Output is correct |
2 |
Correct |
1388 ms |
105496 KB |
Output is correct |
3 |
Correct |
381 ms |
105496 KB |
Output is correct |
4 |
Correct |
1475 ms |
105496 KB |
Output is correct |
5 |
Correct |
1477 ms |
105496 KB |
Output is correct |
6 |
Correct |
1435 ms |
105496 KB |
Output is correct |
7 |
Correct |
365 ms |
105496 KB |
Output is correct |
8 |
Correct |
2024 ms |
111368 KB |
Output is correct |
9 |
Correct |
2138 ms |
114332 KB |
Output is correct |
10 |
Correct |
1053 ms |
114332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
35576 KB |
Output is correct |
2 |
Correct |
71 ms |
71104 KB |
Output is correct |
3 |
Correct |
74 ms |
71104 KB |
Output is correct |
4 |
Correct |
33 ms |
71104 KB |
Output is correct |
5 |
Correct |
33 ms |
71104 KB |
Output is correct |
6 |
Correct |
34 ms |
71104 KB |
Output is correct |
7 |
Correct |
66 ms |
71104 KB |
Output is correct |
8 |
Correct |
34 ms |
71104 KB |
Output is correct |
9 |
Correct |
70 ms |
71236 KB |
Output is correct |
10 |
Correct |
73 ms |
71236 KB |
Output is correct |
11 |
Correct |
71 ms |
114332 KB |
Output is correct |
12 |
Correct |
76 ms |
114332 KB |
Output is correct |
13 |
Correct |
78 ms |
114332 KB |
Output is correct |
14 |
Correct |
76 ms |
114332 KB |
Output is correct |
15 |
Correct |
85 ms |
114332 KB |
Output is correct |
16 |
Correct |
37 ms |
114332 KB |
Output is correct |
17 |
Correct |
76 ms |
114332 KB |
Output is correct |
18 |
Correct |
73 ms |
114332 KB |
Output is correct |
19 |
Correct |
39 ms |
114332 KB |
Output is correct |
20 |
Correct |
77 ms |
114332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
35576 KB |
Output is correct |
2 |
Correct |
71 ms |
71104 KB |
Output is correct |
3 |
Correct |
74 ms |
71104 KB |
Output is correct |
4 |
Correct |
33 ms |
71104 KB |
Output is correct |
5 |
Correct |
33 ms |
71104 KB |
Output is correct |
6 |
Correct |
34 ms |
71104 KB |
Output is correct |
7 |
Correct |
66 ms |
71104 KB |
Output is correct |
8 |
Correct |
34 ms |
71104 KB |
Output is correct |
9 |
Correct |
70 ms |
71236 KB |
Output is correct |
10 |
Correct |
73 ms |
71236 KB |
Output is correct |
11 |
Correct |
71 ms |
114332 KB |
Output is correct |
12 |
Correct |
76 ms |
114332 KB |
Output is correct |
13 |
Correct |
78 ms |
114332 KB |
Output is correct |
14 |
Correct |
76 ms |
114332 KB |
Output is correct |
15 |
Correct |
85 ms |
114332 KB |
Output is correct |
16 |
Correct |
37 ms |
114332 KB |
Output is correct |
17 |
Correct |
76 ms |
114332 KB |
Output is correct |
18 |
Correct |
73 ms |
114332 KB |
Output is correct |
19 |
Correct |
39 ms |
114332 KB |
Output is correct |
20 |
Correct |
77 ms |
114332 KB |
Output is correct |
21 |
Correct |
55 ms |
114332 KB |
Output is correct |
22 |
Correct |
67 ms |
114332 KB |
Output is correct |
23 |
Correct |
81 ms |
114332 KB |
Output is correct |
24 |
Correct |
133 ms |
114332 KB |
Output is correct |
25 |
Correct |
81 ms |
114332 KB |
Output is correct |
26 |
Correct |
117 ms |
114332 KB |
Output is correct |
27 |
Correct |
90 ms |
114332 KB |
Output is correct |
28 |
Correct |
122 ms |
114332 KB |
Output is correct |
29 |
Correct |
97 ms |
114332 KB |
Output is correct |
30 |
Correct |
105 ms |
114332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
35576 KB |
Output is correct |
2 |
Correct |
71 ms |
71104 KB |
Output is correct |
3 |
Correct |
74 ms |
71104 KB |
Output is correct |
4 |
Correct |
33 ms |
71104 KB |
Output is correct |
5 |
Correct |
33 ms |
71104 KB |
Output is correct |
6 |
Correct |
34 ms |
71104 KB |
Output is correct |
7 |
Correct |
66 ms |
71104 KB |
Output is correct |
8 |
Correct |
34 ms |
71104 KB |
Output is correct |
9 |
Correct |
70 ms |
71236 KB |
Output is correct |
10 |
Correct |
73 ms |
71236 KB |
Output is correct |
11 |
Correct |
563 ms |
71236 KB |
Output is correct |
12 |
Correct |
1388 ms |
105496 KB |
Output is correct |
13 |
Correct |
381 ms |
105496 KB |
Output is correct |
14 |
Correct |
1475 ms |
105496 KB |
Output is correct |
15 |
Correct |
1477 ms |
105496 KB |
Output is correct |
16 |
Correct |
1435 ms |
105496 KB |
Output is correct |
17 |
Correct |
365 ms |
105496 KB |
Output is correct |
18 |
Correct |
2024 ms |
111368 KB |
Output is correct |
19 |
Correct |
2138 ms |
114332 KB |
Output is correct |
20 |
Correct |
1053 ms |
114332 KB |
Output is correct |
21 |
Correct |
71 ms |
114332 KB |
Output is correct |
22 |
Correct |
76 ms |
114332 KB |
Output is correct |
23 |
Correct |
78 ms |
114332 KB |
Output is correct |
24 |
Correct |
76 ms |
114332 KB |
Output is correct |
25 |
Correct |
85 ms |
114332 KB |
Output is correct |
26 |
Correct |
37 ms |
114332 KB |
Output is correct |
27 |
Correct |
76 ms |
114332 KB |
Output is correct |
28 |
Correct |
73 ms |
114332 KB |
Output is correct |
29 |
Correct |
39 ms |
114332 KB |
Output is correct |
30 |
Correct |
77 ms |
114332 KB |
Output is correct |
31 |
Correct |
55 ms |
114332 KB |
Output is correct |
32 |
Correct |
67 ms |
114332 KB |
Output is correct |
33 |
Correct |
81 ms |
114332 KB |
Output is correct |
34 |
Correct |
133 ms |
114332 KB |
Output is correct |
35 |
Correct |
81 ms |
114332 KB |
Output is correct |
36 |
Correct |
117 ms |
114332 KB |
Output is correct |
37 |
Correct |
90 ms |
114332 KB |
Output is correct |
38 |
Correct |
122 ms |
114332 KB |
Output is correct |
39 |
Correct |
97 ms |
114332 KB |
Output is correct |
40 |
Correct |
105 ms |
114332 KB |
Output is correct |
41 |
Correct |
334 ms |
114332 KB |
Output is correct |
42 |
Correct |
871 ms |
114332 KB |
Output is correct |
43 |
Correct |
321 ms |
114332 KB |
Output is correct |
44 |
Correct |
354 ms |
114332 KB |
Output is correct |
45 |
Correct |
702 ms |
114332 KB |
Output is correct |
46 |
Correct |
935 ms |
114332 KB |
Output is correct |
47 |
Correct |
1262 ms |
114332 KB |
Output is correct |
48 |
Correct |
384 ms |
114332 KB |
Output is correct |
49 |
Correct |
895 ms |
114332 KB |
Output is correct |
50 |
Correct |
970 ms |
114332 KB |
Output is correct |
51 |
Correct |
386 ms |
114332 KB |
Output is correct |
52 |
Correct |
756 ms |
114332 KB |
Output is correct |
53 |
Correct |
311 ms |
114332 KB |
Output is correct |
54 |
Correct |
1826 ms |
114332 KB |
Output is correct |
55 |
Correct |
1391 ms |
114332 KB |
Output is correct |