//In the name of God
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<ll, ll> pll;
const ll maxn = 1e6 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
ll n, m, t, cntdor, szdor, cnt3, cnt4;
pll e[maxn];
struct gr{
ll x, a[maxn];
bool ok;
gr(ll y = 0){
x = y;
ok = 1;
return;
}
void add(ll v, ll u){
//cout << "! " << x << "\n";
//cout << " add " << v << " " << u << "\n";
if(v == x || u == x) return;
ll av = a[v], au = a[u];
if(av == u || av == -1 || au == -1){
//cout << " --- fail ---- \n";
ok = 0;
return;
}
a[v] = -1;
a[u] = -1;
a[av] = au;
a[au] = av;
//for(ll i = 0; i < n; i++){
// cout << a[i] << " ";
//}
//cout << "\n----------\n";
return;
}
};
vector<ll> g[maxn];
bool ride, done[maxn];
ll dsu[maxn], sz[maxn], dr[maxn];
gr d[20];
ll par(ll v){
if(dsu[v] != v) dsu[v] = par(dsu[v]);
return dsu[v];
}
ll Union(ll v, ll u){
v = par(v);
u = par(u);
if(v == u){
if(dr[v]) return 0;
dr[v] = 1;
return sz[v];
}
if(sz[v] < sz[u]) swap(v, u);
dsu[u] = v;
sz[v] += sz[u];
return 0;
}
void Do(ll v){
if(done[v]) return;
//cout << "# " << t << " -> " << v << "\n";
done[v] = 1;
cnt3++;
d[t].x = v;
d[t].ok = 1;
for(ll i = 0; i < n; i++){
d[t].a[i] = i;
}
for(ll i = 0; i < m; i++){
d[t].add(e[i].F, e[i].S);
}
t++;
return;
}
void Init(int N){
n = N;
for(ll i = 0; i < n; i++){
dsu[i] = i;
sz[i] = 1;
}
}
void Link(int A, int B){
g[A].pb(B);
g[B].pb(A);
if(Sz(g[A]) == 3 && cnt3 < 4){
Do(A);
for(ll u : g[A]){
Do(u);
}
}
if(Sz(g[B]) == 3 && cnt3 < 4){
Do(B);
for(ll u : g[B]){
Do(u);
}
}
if(Sz(g[A]) == 4 && cnt4 < 1){
if(!done[A]){
cnt3--;
cnt4++;
}
Do(A);
}
if(Sz(g[B]) == 4 && cnt4 < 1){
if(!done[B]){
cnt3--;
cnt4++;
}
Do(B);
}
e[m++] = Mp(A, B);
for(ll i = 0; i < t; i++){
d[i].add(A, B);
}
ll x = Union(A, B);
if(x){
if(cntdor) ride = 1;
cntdor++;
szdor += x;
}
return;
}
int CountCritical(){
if(ride) return 0;
if(t == 0){
if(cntdor == 0) return n;
return szdor;
}
ll ans = 0;
for(ll i = 0; i < t; i++){
if(d[i].ok) ans++;
}
return ans;
}
/*int main(){
//fast_io;
ll n, m;
cin >> n >> m;
Init(n);
for(ll i = 0; i < m; i++){
ll x, y;
cin >> x;
if(x == -1){
cout << CountCritical() << "\n";
}
else{
cin >> y;
Link(x, y);
}
}
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24064 KB |
Output is correct |
2 |
Correct |
19 ms |
24300 KB |
Output is correct |
3 |
Correct |
19 ms |
24320 KB |
Output is correct |
4 |
Correct |
17 ms |
24044 KB |
Output is correct |
5 |
Correct |
18 ms |
24172 KB |
Output is correct |
6 |
Correct |
18 ms |
24300 KB |
Output is correct |
7 |
Correct |
18 ms |
24172 KB |
Output is correct |
8 |
Correct |
18 ms |
24172 KB |
Output is correct |
9 |
Correct |
19 ms |
24300 KB |
Output is correct |
10 |
Correct |
19 ms |
24300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
405 ms |
48520 KB |
Output is correct |
2 |
Correct |
1008 ms |
74068 KB |
Output is correct |
3 |
Correct |
1213 ms |
86548 KB |
Output is correct |
4 |
Correct |
1073 ms |
71500 KB |
Output is correct |
5 |
Correct |
1059 ms |
71404 KB |
Output is correct |
6 |
Correct |
1037 ms |
70124 KB |
Output is correct |
7 |
Correct |
1163 ms |
86104 KB |
Output is correct |
8 |
Correct |
1140 ms |
83188 KB |
Output is correct |
9 |
Correct |
1196 ms |
87148 KB |
Output is correct |
10 |
Correct |
693 ms |
69296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24064 KB |
Output is correct |
2 |
Correct |
19 ms |
24300 KB |
Output is correct |
3 |
Correct |
19 ms |
24320 KB |
Output is correct |
4 |
Correct |
17 ms |
24044 KB |
Output is correct |
5 |
Correct |
18 ms |
24172 KB |
Output is correct |
6 |
Correct |
18 ms |
24300 KB |
Output is correct |
7 |
Correct |
18 ms |
24172 KB |
Output is correct |
8 |
Correct |
18 ms |
24172 KB |
Output is correct |
9 |
Correct |
19 ms |
24300 KB |
Output is correct |
10 |
Correct |
19 ms |
24300 KB |
Output is correct |
11 |
Correct |
18 ms |
24428 KB |
Output is correct |
12 |
Correct |
21 ms |
24684 KB |
Output is correct |
13 |
Correct |
22 ms |
24812 KB |
Output is correct |
14 |
Correct |
20 ms |
24556 KB |
Output is correct |
15 |
Correct |
20 ms |
24812 KB |
Output is correct |
16 |
Correct |
22 ms |
24684 KB |
Output is correct |
17 |
Correct |
22 ms |
24812 KB |
Output is correct |
18 |
Correct |
25 ms |
25196 KB |
Output is correct |
19 |
Correct |
22 ms |
24556 KB |
Output is correct |
20 |
Correct |
21 ms |
24812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24064 KB |
Output is correct |
2 |
Correct |
19 ms |
24300 KB |
Output is correct |
3 |
Correct |
19 ms |
24320 KB |
Output is correct |
4 |
Correct |
17 ms |
24044 KB |
Output is correct |
5 |
Correct |
18 ms |
24172 KB |
Output is correct |
6 |
Correct |
18 ms |
24300 KB |
Output is correct |
7 |
Correct |
18 ms |
24172 KB |
Output is correct |
8 |
Correct |
18 ms |
24172 KB |
Output is correct |
9 |
Correct |
19 ms |
24300 KB |
Output is correct |
10 |
Correct |
19 ms |
24300 KB |
Output is correct |
11 |
Correct |
18 ms |
24428 KB |
Output is correct |
12 |
Correct |
21 ms |
24684 KB |
Output is correct |
13 |
Correct |
22 ms |
24812 KB |
Output is correct |
14 |
Correct |
20 ms |
24556 KB |
Output is correct |
15 |
Correct |
20 ms |
24812 KB |
Output is correct |
16 |
Correct |
22 ms |
24684 KB |
Output is correct |
17 |
Correct |
22 ms |
24812 KB |
Output is correct |
18 |
Correct |
25 ms |
25196 KB |
Output is correct |
19 |
Correct |
22 ms |
24556 KB |
Output is correct |
20 |
Correct |
21 ms |
24812 KB |
Output is correct |
21 |
Correct |
37 ms |
25836 KB |
Output is correct |
22 |
Correct |
46 ms |
26860 KB |
Output is correct |
23 |
Correct |
56 ms |
27628 KB |
Output is correct |
24 |
Correct |
64 ms |
28524 KB |
Output is correct |
25 |
Correct |
31 ms |
26988 KB |
Output is correct |
26 |
Correct |
61 ms |
29292 KB |
Output is correct |
27 |
Correct |
60 ms |
28652 KB |
Output is correct |
28 |
Correct |
65 ms |
30060 KB |
Output is correct |
29 |
Correct |
59 ms |
28908 KB |
Output is correct |
30 |
Correct |
75 ms |
28928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24064 KB |
Output is correct |
2 |
Correct |
19 ms |
24300 KB |
Output is correct |
3 |
Correct |
19 ms |
24320 KB |
Output is correct |
4 |
Correct |
17 ms |
24044 KB |
Output is correct |
5 |
Correct |
18 ms |
24172 KB |
Output is correct |
6 |
Correct |
18 ms |
24300 KB |
Output is correct |
7 |
Correct |
18 ms |
24172 KB |
Output is correct |
8 |
Correct |
18 ms |
24172 KB |
Output is correct |
9 |
Correct |
19 ms |
24300 KB |
Output is correct |
10 |
Correct |
19 ms |
24300 KB |
Output is correct |
11 |
Correct |
405 ms |
48520 KB |
Output is correct |
12 |
Correct |
1008 ms |
74068 KB |
Output is correct |
13 |
Correct |
1213 ms |
86548 KB |
Output is correct |
14 |
Correct |
1073 ms |
71500 KB |
Output is correct |
15 |
Correct |
1059 ms |
71404 KB |
Output is correct |
16 |
Correct |
1037 ms |
70124 KB |
Output is correct |
17 |
Correct |
1163 ms |
86104 KB |
Output is correct |
18 |
Correct |
1140 ms |
83188 KB |
Output is correct |
19 |
Correct |
1196 ms |
87148 KB |
Output is correct |
20 |
Correct |
693 ms |
69296 KB |
Output is correct |
21 |
Correct |
18 ms |
24428 KB |
Output is correct |
22 |
Correct |
21 ms |
24684 KB |
Output is correct |
23 |
Correct |
22 ms |
24812 KB |
Output is correct |
24 |
Correct |
20 ms |
24556 KB |
Output is correct |
25 |
Correct |
20 ms |
24812 KB |
Output is correct |
26 |
Correct |
22 ms |
24684 KB |
Output is correct |
27 |
Correct |
22 ms |
24812 KB |
Output is correct |
28 |
Correct |
25 ms |
25196 KB |
Output is correct |
29 |
Correct |
22 ms |
24556 KB |
Output is correct |
30 |
Correct |
21 ms |
24812 KB |
Output is correct |
31 |
Correct |
37 ms |
25836 KB |
Output is correct |
32 |
Correct |
46 ms |
26860 KB |
Output is correct |
33 |
Correct |
56 ms |
27628 KB |
Output is correct |
34 |
Correct |
64 ms |
28524 KB |
Output is correct |
35 |
Correct |
31 ms |
26988 KB |
Output is correct |
36 |
Correct |
61 ms |
29292 KB |
Output is correct |
37 |
Correct |
60 ms |
28652 KB |
Output is correct |
38 |
Correct |
65 ms |
30060 KB |
Output is correct |
39 |
Correct |
59 ms |
28908 KB |
Output is correct |
40 |
Correct |
75 ms |
28928 KB |
Output is correct |
41 |
Correct |
226 ms |
38380 KB |
Output is correct |
42 |
Correct |
536 ms |
63784 KB |
Output is correct |
43 |
Correct |
289 ms |
50156 KB |
Output is correct |
44 |
Correct |
923 ms |
84972 KB |
Output is correct |
45 |
Correct |
822 ms |
77740 KB |
Output is correct |
46 |
Correct |
672 ms |
65644 KB |
Output is correct |
47 |
Correct |
936 ms |
64748 KB |
Output is correct |
48 |
Correct |
578 ms |
71020 KB |
Output is correct |
49 |
Correct |
673 ms |
63724 KB |
Output is correct |
50 |
Correct |
726 ms |
63264 KB |
Output is correct |
51 |
Correct |
324 ms |
49260 KB |
Output is correct |
52 |
Correct |
707 ms |
70508 KB |
Output is correct |
53 |
Correct |
590 ms |
71788 KB |
Output is correct |
54 |
Correct |
1035 ms |
75624 KB |
Output is correct |
55 |
Correct |
1147 ms |
79808 KB |
Output is correct |