#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;
const int inf=1000000010;
const ll INF=1000000000000001000LL;
const int mod=1000000007;
const int MAXN=1000010, LOG=20;
int n, m, k, u, v, x, y, t, a, b;
int tree=1, deg3, ans0, cycle;
int A[MAXN], B[MAXN], deg[MAXN];
vector<int> G[MAXN], V;
struct DSU{
int par[MAXN];
DSU(){
iota(par, par+MAXN, 0);
}
int get(int x){ return (par[x]==x?x:par[x]=get(par[x]));}
int join(int x, int y){
x=get(x);
y=get(y);
par[x]=y;
return x!=y;
}
} dsu;
struct Solver{
int deg[MAXN], root, ok=1;
DSU dsu;
void add_edge(int u, int v){
if (u==root || v==root) return ;
ok&=dsu.join(u, v);
ok&=(2>=++deg[u]);
ok&=(2>=++deg[v]);
}
int Get(){ return ok;}
} solver[4];
void Init(int nn){
n=nn;
}
void Link(int u, int v){
if (ans0) return ;
if (deg3){
for (int i:{0, 1, 2, 3}) solver[i].add_edge(u, v);
return ;
}
A[m]=u;
B[m]=v;
m++;
deg[u]++;
deg[v]++;
if (deg[u]==3) swap(u, v);
if (deg[v]==3){
V={v};
for (int i=0; i<m; i++) if (A[i]==v || B[i]==v) V.pb(v^A[i]^B[i]);
for (int i:{0, 1, 2, 3}){
solver[i].root=V[i];
for (int j=0; j<m; j++) solver[i].add_edge(A[j], B[j]);
}
deg3=1;
return ;
}
if (dsu.join(u, v)) return ;
if (tree){
tree=0;
for (int i=0; i<n; i++) if (dsu.get(i)==dsu.get(v)) cycle++;
}
else ans0=1;
}
int CountCritical(){
if (ans0) return 0;
if (deg3){
int res=0;
for (int i:{0, 1, 2, 3}) res+=solver[i].Get();
return res;
}
if (tree) return n;
return cycle;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
43372 KB |
Output is correct |
2 |
Correct |
31 ms |
43500 KB |
Output is correct |
3 |
Correct |
33 ms |
43628 KB |
Output is correct |
4 |
Correct |
30 ms |
43500 KB |
Output is correct |
5 |
Correct |
31 ms |
43500 KB |
Output is correct |
6 |
Correct |
32 ms |
43500 KB |
Output is correct |
7 |
Correct |
30 ms |
43500 KB |
Output is correct |
8 |
Correct |
31 ms |
43500 KB |
Output is correct |
9 |
Correct |
32 ms |
43628 KB |
Output is correct |
10 |
Correct |
31 ms |
43628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
49516 KB |
Output is correct |
2 |
Correct |
792 ms |
61164 KB |
Output is correct |
3 |
Correct |
1579 ms |
63084 KB |
Output is correct |
4 |
Correct |
468 ms |
55148 KB |
Output is correct |
5 |
Correct |
488 ms |
55148 KB |
Output is correct |
6 |
Correct |
468 ms |
54892 KB |
Output is correct |
7 |
Correct |
1450 ms |
63212 KB |
Output is correct |
8 |
Correct |
865 ms |
66796 KB |
Output is correct |
9 |
Correct |
901 ms |
69612 KB |
Output is correct |
10 |
Correct |
408 ms |
55404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
43372 KB |
Output is correct |
2 |
Correct |
31 ms |
43500 KB |
Output is correct |
3 |
Correct |
33 ms |
43628 KB |
Output is correct |
4 |
Correct |
30 ms |
43500 KB |
Output is correct |
5 |
Correct |
31 ms |
43500 KB |
Output is correct |
6 |
Correct |
32 ms |
43500 KB |
Output is correct |
7 |
Correct |
30 ms |
43500 KB |
Output is correct |
8 |
Correct |
31 ms |
43500 KB |
Output is correct |
9 |
Correct |
32 ms |
43628 KB |
Output is correct |
10 |
Correct |
31 ms |
43628 KB |
Output is correct |
11 |
Correct |
31 ms |
43628 KB |
Output is correct |
12 |
Correct |
34 ms |
43756 KB |
Output is correct |
13 |
Correct |
36 ms |
43756 KB |
Output is correct |
14 |
Correct |
33 ms |
43628 KB |
Output is correct |
15 |
Correct |
33 ms |
43884 KB |
Output is correct |
16 |
Correct |
35 ms |
43628 KB |
Output is correct |
17 |
Correct |
40 ms |
43628 KB |
Output is correct |
18 |
Correct |
34 ms |
43884 KB |
Output is correct |
19 |
Correct |
33 ms |
43628 KB |
Output is correct |
20 |
Correct |
36 ms |
43756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
43372 KB |
Output is correct |
2 |
Correct |
31 ms |
43500 KB |
Output is correct |
3 |
Correct |
33 ms |
43628 KB |
Output is correct |
4 |
Correct |
30 ms |
43500 KB |
Output is correct |
5 |
Correct |
31 ms |
43500 KB |
Output is correct |
6 |
Correct |
32 ms |
43500 KB |
Output is correct |
7 |
Correct |
30 ms |
43500 KB |
Output is correct |
8 |
Correct |
31 ms |
43500 KB |
Output is correct |
9 |
Correct |
32 ms |
43628 KB |
Output is correct |
10 |
Correct |
31 ms |
43628 KB |
Output is correct |
11 |
Correct |
31 ms |
43628 KB |
Output is correct |
12 |
Correct |
34 ms |
43756 KB |
Output is correct |
13 |
Correct |
36 ms |
43756 KB |
Output is correct |
14 |
Correct |
33 ms |
43628 KB |
Output is correct |
15 |
Correct |
33 ms |
43884 KB |
Output is correct |
16 |
Correct |
35 ms |
43628 KB |
Output is correct |
17 |
Correct |
40 ms |
43628 KB |
Output is correct |
18 |
Correct |
34 ms |
43884 KB |
Output is correct |
19 |
Correct |
33 ms |
43628 KB |
Output is correct |
20 |
Correct |
36 ms |
43756 KB |
Output is correct |
21 |
Correct |
43 ms |
44140 KB |
Output is correct |
22 |
Correct |
51 ms |
44396 KB |
Output is correct |
23 |
Correct |
57 ms |
44652 KB |
Output is correct |
24 |
Correct |
70 ms |
45164 KB |
Output is correct |
25 |
Correct |
45 ms |
45292 KB |
Output is correct |
26 |
Correct |
67 ms |
45548 KB |
Output is correct |
27 |
Correct |
58 ms |
44524 KB |
Output is correct |
28 |
Correct |
73 ms |
45292 KB |
Output is correct |
29 |
Correct |
61 ms |
45676 KB |
Output is correct |
30 |
Correct |
60 ms |
44652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
43372 KB |
Output is correct |
2 |
Correct |
31 ms |
43500 KB |
Output is correct |
3 |
Correct |
33 ms |
43628 KB |
Output is correct |
4 |
Correct |
30 ms |
43500 KB |
Output is correct |
5 |
Correct |
31 ms |
43500 KB |
Output is correct |
6 |
Correct |
32 ms |
43500 KB |
Output is correct |
7 |
Correct |
30 ms |
43500 KB |
Output is correct |
8 |
Correct |
31 ms |
43500 KB |
Output is correct |
9 |
Correct |
32 ms |
43628 KB |
Output is correct |
10 |
Correct |
31 ms |
43628 KB |
Output is correct |
11 |
Correct |
208 ms |
49516 KB |
Output is correct |
12 |
Correct |
792 ms |
61164 KB |
Output is correct |
13 |
Correct |
1579 ms |
63084 KB |
Output is correct |
14 |
Correct |
468 ms |
55148 KB |
Output is correct |
15 |
Correct |
488 ms |
55148 KB |
Output is correct |
16 |
Correct |
468 ms |
54892 KB |
Output is correct |
17 |
Correct |
1450 ms |
63212 KB |
Output is correct |
18 |
Correct |
865 ms |
66796 KB |
Output is correct |
19 |
Correct |
901 ms |
69612 KB |
Output is correct |
20 |
Correct |
408 ms |
55404 KB |
Output is correct |
21 |
Correct |
31 ms |
43628 KB |
Output is correct |
22 |
Correct |
34 ms |
43756 KB |
Output is correct |
23 |
Correct |
36 ms |
43756 KB |
Output is correct |
24 |
Correct |
33 ms |
43628 KB |
Output is correct |
25 |
Correct |
33 ms |
43884 KB |
Output is correct |
26 |
Correct |
35 ms |
43628 KB |
Output is correct |
27 |
Correct |
40 ms |
43628 KB |
Output is correct |
28 |
Correct |
34 ms |
43884 KB |
Output is correct |
29 |
Correct |
33 ms |
43628 KB |
Output is correct |
30 |
Correct |
36 ms |
43756 KB |
Output is correct |
31 |
Correct |
43 ms |
44140 KB |
Output is correct |
32 |
Correct |
51 ms |
44396 KB |
Output is correct |
33 |
Correct |
57 ms |
44652 KB |
Output is correct |
34 |
Correct |
70 ms |
45164 KB |
Output is correct |
35 |
Correct |
45 ms |
45292 KB |
Output is correct |
36 |
Correct |
67 ms |
45548 KB |
Output is correct |
37 |
Correct |
58 ms |
44524 KB |
Output is correct |
38 |
Correct |
73 ms |
45292 KB |
Output is correct |
39 |
Correct |
61 ms |
45676 KB |
Output is correct |
40 |
Correct |
60 ms |
44652 KB |
Output is correct |
41 |
Correct |
169 ms |
49132 KB |
Output is correct |
42 |
Correct |
426 ms |
64876 KB |
Output is correct |
43 |
Correct |
292 ms |
60268 KB |
Output is correct |
44 |
Correct |
725 ms |
61932 KB |
Output is correct |
45 |
Correct |
1006 ms |
63964 KB |
Output is correct |
46 |
Correct |
392 ms |
54508 KB |
Output is correct |
47 |
Correct |
445 ms |
54636 KB |
Output is correct |
48 |
Correct |
490 ms |
64876 KB |
Output is correct |
49 |
Correct |
383 ms |
55404 KB |
Output is correct |
50 |
Correct |
400 ms |
55148 KB |
Output is correct |
51 |
Correct |
315 ms |
59884 KB |
Output is correct |
52 |
Correct |
692 ms |
58604 KB |
Output is correct |
53 |
Correct |
477 ms |
64236 KB |
Output is correct |
54 |
Correct |
819 ms |
63340 KB |
Output is correct |
55 |
Correct |
966 ms |
61292 KB |
Output is correct |