#include<bits/stdc++.h>
//#include "rings.h"
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2")
using namespace std;
const int maxn=1000000+10;
vector<int>cand;
int n,tof=0;
struct gr{
pair<int,int>mx;
int par[maxn],sz[maxn],dordare,m,c,moalefedordar;
vector<int>adjs[maxn];
void clear(){
for(int i=0;i<maxn;i++){
par[i]=i;
sz[i]=1;
adjs[i].clear();
}
mx=make_pair(0,-1);
m=0;
dordare=moalefedordar=c=m=0;
}
gr(){
for(int i=0;i<maxn;i++){
par[i]=i;
sz[i]=1;
}
mx=make_pair(0,-1);
m=0;
dordare=moalefedordar=c=m=0;
}
void con(int u,int v){
m++;
if(adjs[u].size()<=3){
adjs[u].push_back(v);
}
if(adjs[v].size()<=3){
adjs[v].push_back(u);
}
mx=max(mx,make_pair((int)adjs[u].size(),u));
mx=max(mx,make_pair((int)adjs[v].size(),v));
if(par[u]==v){
dordare++;
moalefedordar=sz[u];
}else{
c--;
int pu=par[u],pv=par[v],x=sz[u]+sz[v];
sz[pu]=x;
sz[pv]=x;
par[pu]=pv;
par[pv]=pu;
}
}
}gr[4];
void Init(int N){
//int n=N;
n=N;
for(int i=0;i<4;i++){
gr[i].c=n;
}
}
vector<pair<int,int>>getalle(){
vector<pair<int,int>>ret;
for(int i=0;i<n;i++){
for(auto x:gr[0].adjs[i]){
if(x>i){
ret.push_back(make_pair(i,x));
}
}
}
return ret;
}
void Link(int A, int B){
int u=A;
int v=B;
if(tof==0){
gr[0].con(u,v);
}
if((int)cand.size()>0){
for(int i=0;i<4;i++){
if(gr[i].dordare==1||gr[i].mx.first>=3||u==cand[i]||v==cand[i]){
continue;
}
gr[i].con(u,v);
}
}
if(tof==0&&(gr[0].mx).first>=3){
tof=1;
int z=(gr[0].mx).second;
for(auto x:gr[0].adjs[z]){
cand.push_back(x);
}
cand.push_back(z);
vector<pair<int,int>>v=getalle();
gr[0].clear();
for(int i=0;i<(int)cand.size();i++){
for(auto x:v){
if(gr[i].dordare==1||gr[i].mx.first>=3||x.first==cand[i]||x.second==cand[i]){
continue;
}
gr[i].con(x.first,x.second);
}
}
}
}
int CountCritical(){
if(tof){
int res=0;
for(int i=0;i<4;i++){
if(gr[i].dordare==0&&(gr[i].mx).first<3){
res++;
}
}
return res;
}
if(gr[0].dordare==0){
return n;
}
if(gr[0].dordare>=2){
return 0;
}
return gr[0].moalefedordar;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
125524 KB |
Output is correct |
2 |
Correct |
58 ms |
126036 KB |
Output is correct |
3 |
Correct |
50 ms |
126032 KB |
Output is correct |
4 |
Correct |
50 ms |
125524 KB |
Output is correct |
5 |
Correct |
49 ms |
125748 KB |
Output is correct |
6 |
Correct |
52 ms |
125796 KB |
Output is correct |
7 |
Correct |
52 ms |
125696 KB |
Output is correct |
8 |
Correct |
50 ms |
125788 KB |
Output is correct |
9 |
Correct |
58 ms |
126224 KB |
Output is correct |
10 |
Correct |
62 ms |
126372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
216 ms |
148816 KB |
Output is correct |
2 |
Correct |
760 ms |
206612 KB |
Output is correct |
3 |
Correct |
195 ms |
139932 KB |
Output is correct |
4 |
Correct |
552 ms |
170092 KB |
Output is correct |
5 |
Correct |
561 ms |
170324 KB |
Output is correct |
6 |
Correct |
535 ms |
168872 KB |
Output is correct |
7 |
Correct |
199 ms |
140116 KB |
Output is correct |
8 |
Correct |
1280 ms |
251532 KB |
Output is correct |
9 |
Correct |
1372 ms |
262144 KB |
Output is correct |
10 |
Correct |
347 ms |
167736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
125524 KB |
Output is correct |
2 |
Correct |
58 ms |
126036 KB |
Output is correct |
3 |
Correct |
50 ms |
126032 KB |
Output is correct |
4 |
Correct |
50 ms |
125524 KB |
Output is correct |
5 |
Correct |
49 ms |
125748 KB |
Output is correct |
6 |
Correct |
52 ms |
125796 KB |
Output is correct |
7 |
Correct |
52 ms |
125696 KB |
Output is correct |
8 |
Correct |
50 ms |
125788 KB |
Output is correct |
9 |
Correct |
58 ms |
126224 KB |
Output is correct |
10 |
Correct |
62 ms |
126372 KB |
Output is correct |
11 |
Correct |
55 ms |
126292 KB |
Output is correct |
12 |
Correct |
60 ms |
127060 KB |
Output is correct |
13 |
Correct |
65 ms |
127060 KB |
Output is correct |
14 |
Correct |
55 ms |
125880 KB |
Output is correct |
15 |
Correct |
50 ms |
125776 KB |
Output is correct |
16 |
Correct |
52 ms |
126032 KB |
Output is correct |
17 |
Correct |
51 ms |
125788 KB |
Output is correct |
18 |
Correct |
50 ms |
125776 KB |
Output is correct |
19 |
Correct |
56 ms |
126288 KB |
Output is correct |
20 |
Correct |
61 ms |
126804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
125524 KB |
Output is correct |
2 |
Correct |
58 ms |
126036 KB |
Output is correct |
3 |
Correct |
50 ms |
126032 KB |
Output is correct |
4 |
Correct |
50 ms |
125524 KB |
Output is correct |
5 |
Correct |
49 ms |
125748 KB |
Output is correct |
6 |
Correct |
52 ms |
125796 KB |
Output is correct |
7 |
Correct |
52 ms |
125696 KB |
Output is correct |
8 |
Correct |
50 ms |
125788 KB |
Output is correct |
9 |
Correct |
58 ms |
126224 KB |
Output is correct |
10 |
Correct |
62 ms |
126372 KB |
Output is correct |
11 |
Correct |
55 ms |
126292 KB |
Output is correct |
12 |
Correct |
60 ms |
127060 KB |
Output is correct |
13 |
Correct |
65 ms |
127060 KB |
Output is correct |
14 |
Correct |
55 ms |
125880 KB |
Output is correct |
15 |
Correct |
50 ms |
125776 KB |
Output is correct |
16 |
Correct |
52 ms |
126032 KB |
Output is correct |
17 |
Correct |
51 ms |
125788 KB |
Output is correct |
18 |
Correct |
50 ms |
125776 KB |
Output is correct |
19 |
Correct |
56 ms |
126288 KB |
Output is correct |
20 |
Correct |
61 ms |
126804 KB |
Output is correct |
21 |
Correct |
62 ms |
126996 KB |
Output is correct |
22 |
Correct |
65 ms |
127836 KB |
Output is correct |
23 |
Correct |
69 ms |
128296 KB |
Output is correct |
24 |
Correct |
73 ms |
127824 KB |
Output is correct |
25 |
Correct |
57 ms |
126036 KB |
Output is correct |
26 |
Correct |
80 ms |
128600 KB |
Output is correct |
27 |
Correct |
72 ms |
129312 KB |
Output is correct |
28 |
Correct |
74 ms |
126800 KB |
Output is correct |
29 |
Correct |
67 ms |
126800 KB |
Output is correct |
30 |
Correct |
77 ms |
129876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
125524 KB |
Output is correct |
2 |
Correct |
58 ms |
126036 KB |
Output is correct |
3 |
Correct |
50 ms |
126032 KB |
Output is correct |
4 |
Correct |
50 ms |
125524 KB |
Output is correct |
5 |
Correct |
49 ms |
125748 KB |
Output is correct |
6 |
Correct |
52 ms |
125796 KB |
Output is correct |
7 |
Correct |
52 ms |
125696 KB |
Output is correct |
8 |
Correct |
50 ms |
125788 KB |
Output is correct |
9 |
Correct |
58 ms |
126224 KB |
Output is correct |
10 |
Correct |
62 ms |
126372 KB |
Output is correct |
11 |
Correct |
216 ms |
148816 KB |
Output is correct |
12 |
Correct |
760 ms |
206612 KB |
Output is correct |
13 |
Correct |
195 ms |
139932 KB |
Output is correct |
14 |
Correct |
552 ms |
170092 KB |
Output is correct |
15 |
Correct |
561 ms |
170324 KB |
Output is correct |
16 |
Correct |
535 ms |
168872 KB |
Output is correct |
17 |
Correct |
199 ms |
140116 KB |
Output is correct |
18 |
Correct |
1280 ms |
251532 KB |
Output is correct |
19 |
Correct |
1372 ms |
262144 KB |
Output is correct |
20 |
Correct |
347 ms |
167736 KB |
Output is correct |
21 |
Correct |
55 ms |
126292 KB |
Output is correct |
22 |
Correct |
60 ms |
127060 KB |
Output is correct |
23 |
Correct |
65 ms |
127060 KB |
Output is correct |
24 |
Correct |
55 ms |
125880 KB |
Output is correct |
25 |
Correct |
50 ms |
125776 KB |
Output is correct |
26 |
Correct |
52 ms |
126032 KB |
Output is correct |
27 |
Correct |
51 ms |
125788 KB |
Output is correct |
28 |
Correct |
50 ms |
125776 KB |
Output is correct |
29 |
Correct |
56 ms |
126288 KB |
Output is correct |
30 |
Correct |
61 ms |
126804 KB |
Output is correct |
31 |
Correct |
62 ms |
126996 KB |
Output is correct |
32 |
Correct |
65 ms |
127836 KB |
Output is correct |
33 |
Correct |
69 ms |
128296 KB |
Output is correct |
34 |
Correct |
73 ms |
127824 KB |
Output is correct |
35 |
Correct |
57 ms |
126036 KB |
Output is correct |
36 |
Correct |
80 ms |
128600 KB |
Output is correct |
37 |
Correct |
72 ms |
129312 KB |
Output is correct |
38 |
Correct |
74 ms |
126800 KB |
Output is correct |
39 |
Correct |
67 ms |
126800 KB |
Output is correct |
40 |
Correct |
77 ms |
129876 KB |
Output is correct |
41 |
Correct |
155 ms |
137552 KB |
Output is correct |
42 |
Correct |
611 ms |
189716 KB |
Output is correct |
43 |
Correct |
154 ms |
132692 KB |
Output is correct |
44 |
Correct |
171 ms |
138324 KB |
Output is correct |
45 |
Correct |
394 ms |
154052 KB |
Output is correct |
46 |
Correct |
357 ms |
163896 KB |
Output is correct |
47 |
Correct |
473 ms |
164436 KB |
Output is correct |
48 |
Correct |
171 ms |
136148 KB |
Output is correct |
49 |
Correct |
354 ms |
161560 KB |
Output is correct |
50 |
Correct |
399 ms |
161284 KB |
Output is correct |
51 |
Correct |
164 ms |
134740 KB |
Output is correct |
52 |
Correct |
189 ms |
137040 KB |
Output is correct |
53 |
Correct |
154 ms |
134480 KB |
Output is correct |
54 |
Correct |
1070 ms |
231300 KB |
Output is correct |
55 |
Correct |
534 ms |
166404 KB |
Output is correct |