#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<'('<<P.F<<','<<P.S<<')';
return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
return out;
}
#define version 20190726
//}}}
const ll maxn=1000005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;
ll mypow(ll a,ll b){
ll res=1LL;
while(b){
if(b&1) res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
struct DSU{
int dsu[maxn];
int sz[maxn];
DSU(){}
void init(int n){
REP(i,n) dsu[i]=i,sz[i]=1;
}
int find(int u){
if(dsu[u]==u) return u;
return dsu[u]=find(dsu[u]);
}
void mrg(int u,int v){
u=find(u);
v=find(v);
if(u==v) return;
if(sz[u]<sz[v]) swap(u,v);
dsu[v]=u;
sz[u]+=sz[v];
}
};
struct checker{
int dsu[maxn];
int sz[maxn];
int deg[maxn];
bool valid=1;
checker(){}
void init(int n){
REP(i,n) dsu[i]=i,sz[i]=1;
}
int find(int u){
if(dsu[u]==u) return u;
return dsu[u]=find(dsu[u]);
}
void mrg(int u,int v){
deg[u]++,deg[v]++;
if(deg[u]==3||deg[v]==3) valid=0;
u=find(u);
v=find(v);
if(u==v){
valid=0;
return;
}
if(sz[u]<sz[v]) swap(u,v);
dsu[v]=u;
sz[u]+=sz[v];
}
};
int n;
bool stage=0;
int deg[maxn];
vector<int> edge[maxn];
vector<int> p;
DSU orig;
int ring=0;
int ringsz=-1;
checker nw[5];
void Init(int N){
n=N;
orig.init(N);
}
void Link(int A, int B) {
deg[A]++;
deg[B]++;
edge[A].pb(B);
edge[B].pb(A);
bool f=0;
if((!stage)&&(deg[A]==3)){
f=1;
stage=1;
p.pb(A);
for(int i:edge[A]) p.pb(i);
REP(i,SZ(p)){
nw[i].init(n);
REP(j,n) for(int k:edge[j]){
if(j<k&&j!=p[i]&&k!=p[i]){
nw[i].mrg(j,k);
}
}
}
}
if((!stage)&&(deg[B]==3)){
f=1;
stage=1;
p.pb(B);
for(int i:edge[B]) p.pb(i);
REP(i,SZ(p)){
nw[i].init(n);
REP(j,n) for(int k:edge[j]){
if(j<k&&j!=p[i]&&k!=p[i]){
nw[i].mrg(j,k);
}
}
}
}
if(stage==0){
if(orig.find(A)==orig.find(B)){
ring++;
if(ring==1){
ringsz=orig.sz[orig.find(A)];
}
}
else{
orig.mrg(A,B);
}
}
else{
if(f);
else{
REP(i,SZ(p)){
if(p[i]!=A&&p[i]!=B){
nw[i].mrg(A,B);
}
}
}
}
}
int CountCritical() {
if(stage){
int ans=0;
REP(i,4) ans+=nw[i].valid;
return ans;
}
else{
if(ring>=2){
return 0;
}
if(ring==1) return ringsz;
return n;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
27 ms |
24312 KB |
Output is correct |
3 |
Correct |
27 ms |
24440 KB |
Output is correct |
4 |
Correct |
25 ms |
23928 KB |
Output is correct |
5 |
Correct |
26 ms |
24056 KB |
Output is correct |
6 |
Correct |
30 ms |
24184 KB |
Output is correct |
7 |
Correct |
24 ms |
24312 KB |
Output is correct |
8 |
Correct |
25 ms |
24056 KB |
Output is correct |
9 |
Correct |
28 ms |
24440 KB |
Output is correct |
10 |
Correct |
32 ms |
24440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
501 ms |
53168 KB |
Output is correct |
2 |
Correct |
1888 ms |
106752 KB |
Output is correct |
3 |
Correct |
2086 ms |
122744 KB |
Output is correct |
4 |
Correct |
1322 ms |
80276 KB |
Output is correct |
5 |
Correct |
1343 ms |
80420 KB |
Output is correct |
6 |
Correct |
1287 ms |
78900 KB |
Output is correct |
7 |
Correct |
2097 ms |
121516 KB |
Output is correct |
8 |
Correct |
2299 ms |
120808 KB |
Output is correct |
9 |
Correct |
2397 ms |
127180 KB |
Output is correct |
10 |
Correct |
974 ms |
77944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
27 ms |
24312 KB |
Output is correct |
3 |
Correct |
27 ms |
24440 KB |
Output is correct |
4 |
Correct |
25 ms |
23928 KB |
Output is correct |
5 |
Correct |
26 ms |
24056 KB |
Output is correct |
6 |
Correct |
30 ms |
24184 KB |
Output is correct |
7 |
Correct |
24 ms |
24312 KB |
Output is correct |
8 |
Correct |
25 ms |
24056 KB |
Output is correct |
9 |
Correct |
28 ms |
24440 KB |
Output is correct |
10 |
Correct |
32 ms |
24440 KB |
Output is correct |
11 |
Correct |
27 ms |
24440 KB |
Output is correct |
12 |
Correct |
31 ms |
24952 KB |
Output is correct |
13 |
Correct |
31 ms |
24952 KB |
Output is correct |
14 |
Correct |
29 ms |
24740 KB |
Output is correct |
15 |
Correct |
29 ms |
25336 KB |
Output is correct |
16 |
Correct |
29 ms |
24568 KB |
Output is correct |
17 |
Correct |
32 ms |
24952 KB |
Output is correct |
18 |
Correct |
33 ms |
25684 KB |
Output is correct |
19 |
Correct |
35 ms |
24440 KB |
Output is correct |
20 |
Correct |
31 ms |
24952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
27 ms |
24312 KB |
Output is correct |
3 |
Correct |
27 ms |
24440 KB |
Output is correct |
4 |
Correct |
25 ms |
23928 KB |
Output is correct |
5 |
Correct |
26 ms |
24056 KB |
Output is correct |
6 |
Correct |
30 ms |
24184 KB |
Output is correct |
7 |
Correct |
24 ms |
24312 KB |
Output is correct |
8 |
Correct |
25 ms |
24056 KB |
Output is correct |
9 |
Correct |
28 ms |
24440 KB |
Output is correct |
10 |
Correct |
32 ms |
24440 KB |
Output is correct |
11 |
Correct |
27 ms |
24440 KB |
Output is correct |
12 |
Correct |
31 ms |
24952 KB |
Output is correct |
13 |
Correct |
31 ms |
24952 KB |
Output is correct |
14 |
Correct |
29 ms |
24740 KB |
Output is correct |
15 |
Correct |
29 ms |
25336 KB |
Output is correct |
16 |
Correct |
29 ms |
24568 KB |
Output is correct |
17 |
Correct |
32 ms |
24952 KB |
Output is correct |
18 |
Correct |
33 ms |
25684 KB |
Output is correct |
19 |
Correct |
35 ms |
24440 KB |
Output is correct |
20 |
Correct |
31 ms |
24952 KB |
Output is correct |
21 |
Correct |
46 ms |
25948 KB |
Output is correct |
22 |
Correct |
72 ms |
27012 KB |
Output is correct |
23 |
Correct |
72 ms |
27836 KB |
Output is correct |
24 |
Correct |
110 ms |
31876 KB |
Output is correct |
25 |
Correct |
44 ms |
30328 KB |
Output is correct |
26 |
Correct |
91 ms |
32560 KB |
Output is correct |
27 |
Correct |
82 ms |
28696 KB |
Output is correct |
28 |
Correct |
112 ms |
32964 KB |
Output is correct |
29 |
Correct |
86 ms |
31992 KB |
Output is correct |
30 |
Correct |
100 ms |
29304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
27 ms |
24312 KB |
Output is correct |
3 |
Correct |
27 ms |
24440 KB |
Output is correct |
4 |
Correct |
25 ms |
23928 KB |
Output is correct |
5 |
Correct |
26 ms |
24056 KB |
Output is correct |
6 |
Correct |
30 ms |
24184 KB |
Output is correct |
7 |
Correct |
24 ms |
24312 KB |
Output is correct |
8 |
Correct |
25 ms |
24056 KB |
Output is correct |
9 |
Correct |
28 ms |
24440 KB |
Output is correct |
10 |
Correct |
32 ms |
24440 KB |
Output is correct |
11 |
Correct |
501 ms |
53168 KB |
Output is correct |
12 |
Correct |
1888 ms |
106752 KB |
Output is correct |
13 |
Correct |
2086 ms |
122744 KB |
Output is correct |
14 |
Correct |
1322 ms |
80276 KB |
Output is correct |
15 |
Correct |
1343 ms |
80420 KB |
Output is correct |
16 |
Correct |
1287 ms |
78900 KB |
Output is correct |
17 |
Correct |
2097 ms |
121516 KB |
Output is correct |
18 |
Correct |
2299 ms |
120808 KB |
Output is correct |
19 |
Correct |
2397 ms |
127180 KB |
Output is correct |
20 |
Correct |
974 ms |
77944 KB |
Output is correct |
21 |
Correct |
27 ms |
24440 KB |
Output is correct |
22 |
Correct |
31 ms |
24952 KB |
Output is correct |
23 |
Correct |
31 ms |
24952 KB |
Output is correct |
24 |
Correct |
29 ms |
24740 KB |
Output is correct |
25 |
Correct |
29 ms |
25336 KB |
Output is correct |
26 |
Correct |
29 ms |
24568 KB |
Output is correct |
27 |
Correct |
32 ms |
24952 KB |
Output is correct |
28 |
Correct |
33 ms |
25684 KB |
Output is correct |
29 |
Correct |
35 ms |
24440 KB |
Output is correct |
30 |
Correct |
31 ms |
24952 KB |
Output is correct |
31 |
Correct |
46 ms |
25948 KB |
Output is correct |
32 |
Correct |
72 ms |
27012 KB |
Output is correct |
33 |
Correct |
72 ms |
27836 KB |
Output is correct |
34 |
Correct |
110 ms |
31876 KB |
Output is correct |
35 |
Correct |
44 ms |
30328 KB |
Output is correct |
36 |
Correct |
91 ms |
32560 KB |
Output is correct |
37 |
Correct |
82 ms |
28696 KB |
Output is correct |
38 |
Correct |
112 ms |
32964 KB |
Output is correct |
39 |
Correct |
86 ms |
31992 KB |
Output is correct |
40 |
Correct |
100 ms |
29304 KB |
Output is correct |
41 |
Correct |
278 ms |
41820 KB |
Output is correct |
42 |
Correct |
1029 ms |
96056 KB |
Output is correct |
43 |
Correct |
386 ms |
85288 KB |
Output is correct |
44 |
Correct |
1418 ms |
118508 KB |
Output is correct |
45 |
Correct |
1417 ms |
112268 KB |
Output is correct |
46 |
Correct |
968 ms |
71760 KB |
Output is correct |
47 |
Correct |
1129 ms |
72504 KB |
Output is correct |
48 |
Correct |
965 ms |
105556 KB |
Output is correct |
49 |
Correct |
877 ms |
71672 KB |
Output is correct |
50 |
Correct |
917 ms |
71248 KB |
Output is correct |
51 |
Correct |
496 ms |
79388 KB |
Output is correct |
52 |
Correct |
1266 ms |
100344 KB |
Output is correct |
53 |
Correct |
934 ms |
106044 KB |
Output is correct |
54 |
Correct |
1920 ms |
108284 KB |
Output is correct |
55 |
Correct |
2110 ms |
115564 KB |
Output is correct |