// 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;
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 >= 3 && cycles.size() == 1)
over = 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;
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){
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:93:2: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
35576 KB |
Output is correct |
2 |
Correct |
87 ms |
94584 KB |
Output is correct |
3 |
Correct |
83 ms |
94632 KB |
Output is correct |
4 |
Correct |
33 ms |
94632 KB |
Output is correct |
5 |
Correct |
34 ms |
94632 KB |
Output is correct |
6 |
Correct |
35 ms |
94632 KB |
Output is correct |
7 |
Correct |
71 ms |
94632 KB |
Output is correct |
8 |
Correct |
34 ms |
94632 KB |
Output is correct |
9 |
Correct |
74 ms |
94632 KB |
Output is correct |
10 |
Correct |
76 ms |
94632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
571 ms |
94632 KB |
Output is correct |
2 |
Correct |
1500 ms |
128976 KB |
Output is correct |
3 |
Correct |
1137 ms |
133332 KB |
Output is correct |
4 |
Correct |
1676 ms |
133332 KB |
Output is correct |
5 |
Correct |
1664 ms |
133332 KB |
Output is correct |
6 |
Correct |
1631 ms |
133332 KB |
Output is correct |
7 |
Correct |
1075 ms |
133332 KB |
Output is correct |
8 |
Correct |
2290 ms |
133332 KB |
Output is correct |
9 |
Correct |
2388 ms |
133332 KB |
Output is correct |
10 |
Correct |
1047 ms |
133332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
35576 KB |
Output is correct |
2 |
Correct |
87 ms |
94584 KB |
Output is correct |
3 |
Correct |
83 ms |
94632 KB |
Output is correct |
4 |
Correct |
33 ms |
94632 KB |
Output is correct |
5 |
Correct |
34 ms |
94632 KB |
Output is correct |
6 |
Correct |
35 ms |
94632 KB |
Output is correct |
7 |
Correct |
71 ms |
94632 KB |
Output is correct |
8 |
Correct |
34 ms |
94632 KB |
Output is correct |
9 |
Correct |
74 ms |
94632 KB |
Output is correct |
10 |
Correct |
76 ms |
94632 KB |
Output is correct |
11 |
Correct |
86 ms |
133332 KB |
Output is correct |
12 |
Correct |
87 ms |
133332 KB |
Output is correct |
13 |
Correct |
89 ms |
133332 KB |
Output is correct |
14 |
Correct |
85 ms |
133332 KB |
Output is correct |
15 |
Correct |
86 ms |
133332 KB |
Output is correct |
16 |
Correct |
38 ms |
133332 KB |
Output is correct |
17 |
Correct |
77 ms |
133332 KB |
Output is correct |
18 |
Correct |
87 ms |
133332 KB |
Output is correct |
19 |
Correct |
37 ms |
133332 KB |
Output is correct |
20 |
Correct |
82 ms |
133332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
35576 KB |
Output is correct |
2 |
Correct |
87 ms |
94584 KB |
Output is correct |
3 |
Correct |
83 ms |
94632 KB |
Output is correct |
4 |
Correct |
33 ms |
94632 KB |
Output is correct |
5 |
Correct |
34 ms |
94632 KB |
Output is correct |
6 |
Correct |
35 ms |
94632 KB |
Output is correct |
7 |
Correct |
71 ms |
94632 KB |
Output is correct |
8 |
Correct |
34 ms |
94632 KB |
Output is correct |
9 |
Correct |
74 ms |
94632 KB |
Output is correct |
10 |
Correct |
76 ms |
94632 KB |
Output is correct |
11 |
Correct |
86 ms |
133332 KB |
Output is correct |
12 |
Correct |
87 ms |
133332 KB |
Output is correct |
13 |
Correct |
89 ms |
133332 KB |
Output is correct |
14 |
Correct |
85 ms |
133332 KB |
Output is correct |
15 |
Correct |
86 ms |
133332 KB |
Output is correct |
16 |
Correct |
38 ms |
133332 KB |
Output is correct |
17 |
Correct |
77 ms |
133332 KB |
Output is correct |
18 |
Correct |
87 ms |
133332 KB |
Output is correct |
19 |
Correct |
37 ms |
133332 KB |
Output is correct |
20 |
Correct |
82 ms |
133332 KB |
Output is correct |
21 |
Correct |
53 ms |
133332 KB |
Output is correct |
22 |
Correct |
70 ms |
133332 KB |
Output is correct |
23 |
Correct |
82 ms |
133332 KB |
Output is correct |
24 |
Correct |
133 ms |
133332 KB |
Output is correct |
25 |
Correct |
94 ms |
133332 KB |
Output is correct |
26 |
Correct |
133 ms |
133332 KB |
Output is correct |
27 |
Correct |
93 ms |
133332 KB |
Output is correct |
28 |
Correct |
125 ms |
133332 KB |
Output is correct |
29 |
Correct |
130 ms |
133332 KB |
Output is correct |
30 |
Correct |
112 ms |
133332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
35576 KB |
Output is correct |
2 |
Correct |
87 ms |
94584 KB |
Output is correct |
3 |
Correct |
83 ms |
94632 KB |
Output is correct |
4 |
Correct |
33 ms |
94632 KB |
Output is correct |
5 |
Correct |
34 ms |
94632 KB |
Output is correct |
6 |
Correct |
35 ms |
94632 KB |
Output is correct |
7 |
Correct |
71 ms |
94632 KB |
Output is correct |
8 |
Correct |
34 ms |
94632 KB |
Output is correct |
9 |
Correct |
74 ms |
94632 KB |
Output is correct |
10 |
Correct |
76 ms |
94632 KB |
Output is correct |
11 |
Correct |
571 ms |
94632 KB |
Output is correct |
12 |
Correct |
1500 ms |
128976 KB |
Output is correct |
13 |
Correct |
1137 ms |
133332 KB |
Output is correct |
14 |
Correct |
1676 ms |
133332 KB |
Output is correct |
15 |
Correct |
1664 ms |
133332 KB |
Output is correct |
16 |
Correct |
1631 ms |
133332 KB |
Output is correct |
17 |
Correct |
1075 ms |
133332 KB |
Output is correct |
18 |
Correct |
2290 ms |
133332 KB |
Output is correct |
19 |
Correct |
2388 ms |
133332 KB |
Output is correct |
20 |
Correct |
1047 ms |
133332 KB |
Output is correct |
21 |
Correct |
86 ms |
133332 KB |
Output is correct |
22 |
Correct |
87 ms |
133332 KB |
Output is correct |
23 |
Correct |
89 ms |
133332 KB |
Output is correct |
24 |
Correct |
85 ms |
133332 KB |
Output is correct |
25 |
Correct |
86 ms |
133332 KB |
Output is correct |
26 |
Correct |
38 ms |
133332 KB |
Output is correct |
27 |
Correct |
77 ms |
133332 KB |
Output is correct |
28 |
Correct |
87 ms |
133332 KB |
Output is correct |
29 |
Correct |
37 ms |
133332 KB |
Output is correct |
30 |
Correct |
82 ms |
133332 KB |
Output is correct |
31 |
Correct |
53 ms |
133332 KB |
Output is correct |
32 |
Correct |
70 ms |
133332 KB |
Output is correct |
33 |
Correct |
82 ms |
133332 KB |
Output is correct |
34 |
Correct |
133 ms |
133332 KB |
Output is correct |
35 |
Correct |
94 ms |
133332 KB |
Output is correct |
36 |
Correct |
133 ms |
133332 KB |
Output is correct |
37 |
Correct |
93 ms |
133332 KB |
Output is correct |
38 |
Correct |
125 ms |
133332 KB |
Output is correct |
39 |
Correct |
130 ms |
133332 KB |
Output is correct |
40 |
Correct |
112 ms |
133332 KB |
Output is correct |
41 |
Correct |
300 ms |
133332 KB |
Output is correct |
42 |
Correct |
976 ms |
133332 KB |
Output is correct |
43 |
Correct |
386 ms |
133332 KB |
Output is correct |
44 |
Correct |
828 ms |
133332 KB |
Output is correct |
45 |
Correct |
1131 ms |
133332 KB |
Output is correct |
46 |
Correct |
1018 ms |
133332 KB |
Output is correct |
47 |
Correct |
1386 ms |
133332 KB |
Output is correct |
48 |
Correct |
610 ms |
133332 KB |
Output is correct |
49 |
Correct |
1008 ms |
133332 KB |
Output is correct |
50 |
Correct |
1138 ms |
133332 KB |
Output is correct |
51 |
Correct |
407 ms |
133332 KB |
Output is correct |
52 |
Correct |
736 ms |
133332 KB |
Output is correct |
53 |
Correct |
627 ms |
133332 KB |
Output is correct |
54 |
Correct |
1905 ms |
133332 KB |
Output is correct |
55 |
Correct |
1596 ms |
133332 KB |
Output is correct |