#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<ii> vii;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define RE(a,b) REP(a,0,b)
#define RE1(a,b) REP(a,1,b+1)
#define FOR(a,b) for(auto& a : b)
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), e.end()
const int MX = 1e6+10;
int n;
struct DSU {
int p[MX], r[MX], sz[MX], e[MX][2];
int cnt[MX];
int bigCnt = 0, smallCnt = 0;
int cycles = 0, cycleLength = 0;
void build() {
RE(i,n) p[i] = i, r[i]=0, e[i][0]=e[i][1]=i, sz[i] = 1;
RE(i,n) cnt[i] = 0;
}
int getSet(int x) {return x==p[x] ? x : p[x]=getSet(p[x]);}
void link(int x, int y) {
cnt[x]++;
cnt[y]++;
if(cnt[x] == 4) bigCnt++;
if(cnt[y] == 4) bigCnt++;
if(cnt[x] == 3) smallCnt++;
if(cnt[y] == 3) smallCnt++;
int u = getSet(x), v = getSet(y);
if((e[u][0] == x && e[u][1] == y) || (e[u][0] == y && e[u][1] == x)) {
cycles++;
cycleLength = sz[u];
return;
}
if(u != v) {
sz[u] = sz[v] = sz[u] + sz[v];
int i = 0, j = 0;
if(e[u][0] != x) i = 1;
if(e[v][0] != y) j = 1;
e[u][i] = e[v][!j];
RE(i,2) e[v][i] = e[u][i];
if(r[u] > r[v]) {
p[v] = u;
} else {
p[u] = v;
if(r[u] == r[v]) r[v]++;
}
}
}
};
DSU g;
vi adj[MX];
vii opperations;
bool started = false;
DSU other[4]; int ign[4];
void Init(int N_) {
n = N_;
g.build();
}
void createGraph(int i) {
other[i].build();
FOR(p,opperations) {
int A = p.fi, B = p.se;
if(A == ign[i] || B == ign[i])
continue;
other[i].link(A,B);
}
}
void Link(int A, int B) {
adj[A].pb(B);
adj[B].pb(A);
opperations.pb({A,B});
g.link(A,B);
if(started) {
RE(i,4) {
if(A == ign[i] || B == ign[i])
continue;
other[i].link(A,B);
}
}
else if(adj[A].size() == 3 || adj[B].size() == 3) {
int u = A;
if(adj[B].size() == 3) u = B;
ign[0] = u; int i=0;
FOR(v,adj[u]) ign[++i] = v;
RE(i,4) createGraph(i);
started = true;
}
}
int CountCritical() {
if(g.bigCnt >= 2)
return 0;
if(started) {
int cnt = 0;
RE(i,4)
if(other[i].cycles == 0 && other[i].smallCnt == 0)
cnt++;
return cnt;
}
if(g.cycles == 0)
return n;
if(g.cycles >= 2)
return 0;
return g.cycleLength;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23824 KB |
Output is correct |
2 |
Correct |
17 ms |
24652 KB |
Output is correct |
3 |
Correct |
17 ms |
24772 KB |
Output is correct |
4 |
Correct |
14 ms |
23824 KB |
Output is correct |
5 |
Correct |
15 ms |
24104 KB |
Output is correct |
6 |
Correct |
17 ms |
24164 KB |
Output is correct |
7 |
Correct |
16 ms |
24516 KB |
Output is correct |
8 |
Correct |
15 ms |
24140 KB |
Output is correct |
9 |
Correct |
17 ms |
24780 KB |
Output is correct |
10 |
Correct |
17 ms |
24896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
562 ms |
57604 KB |
Output is correct |
2 |
Correct |
2457 ms |
149804 KB |
Output is correct |
3 |
Correct |
2758 ms |
176092 KB |
Output is correct |
4 |
Correct |
1430 ms |
86568 KB |
Output is correct |
5 |
Correct |
1414 ms |
99804 KB |
Output is correct |
6 |
Correct |
1378 ms |
98000 KB |
Output is correct |
7 |
Correct |
2674 ms |
187100 KB |
Output is correct |
8 |
Correct |
2823 ms |
182844 KB |
Output is correct |
9 |
Correct |
2932 ms |
193620 KB |
Output is correct |
10 |
Correct |
965 ms |
96936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23824 KB |
Output is correct |
2 |
Correct |
17 ms |
24652 KB |
Output is correct |
3 |
Correct |
17 ms |
24772 KB |
Output is correct |
4 |
Correct |
14 ms |
23824 KB |
Output is correct |
5 |
Correct |
15 ms |
24104 KB |
Output is correct |
6 |
Correct |
17 ms |
24164 KB |
Output is correct |
7 |
Correct |
16 ms |
24516 KB |
Output is correct |
8 |
Correct |
15 ms |
24140 KB |
Output is correct |
9 |
Correct |
17 ms |
24780 KB |
Output is correct |
10 |
Correct |
17 ms |
24896 KB |
Output is correct |
11 |
Correct |
22 ms |
24776 KB |
Output is correct |
12 |
Correct |
21 ms |
25604 KB |
Output is correct |
13 |
Correct |
21 ms |
25692 KB |
Output is correct |
14 |
Correct |
20 ms |
25420 KB |
Output is correct |
15 |
Correct |
21 ms |
26644 KB |
Output is correct |
16 |
Correct |
24 ms |
24564 KB |
Output is correct |
17 |
Correct |
24 ms |
25684 KB |
Output is correct |
18 |
Correct |
26 ms |
26864 KB |
Output is correct |
19 |
Correct |
20 ms |
24688 KB |
Output is correct |
20 |
Correct |
23 ms |
25676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23824 KB |
Output is correct |
2 |
Correct |
17 ms |
24652 KB |
Output is correct |
3 |
Correct |
17 ms |
24772 KB |
Output is correct |
4 |
Correct |
14 ms |
23824 KB |
Output is correct |
5 |
Correct |
15 ms |
24104 KB |
Output is correct |
6 |
Correct |
17 ms |
24164 KB |
Output is correct |
7 |
Correct |
16 ms |
24516 KB |
Output is correct |
8 |
Correct |
15 ms |
24140 KB |
Output is correct |
9 |
Correct |
17 ms |
24780 KB |
Output is correct |
10 |
Correct |
17 ms |
24896 KB |
Output is correct |
11 |
Correct |
22 ms |
24776 KB |
Output is correct |
12 |
Correct |
21 ms |
25604 KB |
Output is correct |
13 |
Correct |
21 ms |
25692 KB |
Output is correct |
14 |
Correct |
20 ms |
25420 KB |
Output is correct |
15 |
Correct |
21 ms |
26644 KB |
Output is correct |
16 |
Correct |
24 ms |
24564 KB |
Output is correct |
17 |
Correct |
24 ms |
25684 KB |
Output is correct |
18 |
Correct |
26 ms |
26864 KB |
Output is correct |
19 |
Correct |
20 ms |
24688 KB |
Output is correct |
20 |
Correct |
23 ms |
25676 KB |
Output is correct |
21 |
Correct |
51 ms |
26572 KB |
Output is correct |
22 |
Correct |
70 ms |
28124 KB |
Output is correct |
23 |
Correct |
66 ms |
29452 KB |
Output is correct |
24 |
Correct |
181 ms |
37520 KB |
Output is correct |
25 |
Correct |
41 ms |
36228 KB |
Output is correct |
26 |
Correct |
133 ms |
38588 KB |
Output is correct |
27 |
Correct |
84 ms |
30220 KB |
Output is correct |
28 |
Correct |
156 ms |
38772 KB |
Output is correct |
29 |
Correct |
95 ms |
38096 KB |
Output is correct |
30 |
Correct |
101 ms |
31128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23824 KB |
Output is correct |
2 |
Correct |
17 ms |
24652 KB |
Output is correct |
3 |
Correct |
17 ms |
24772 KB |
Output is correct |
4 |
Correct |
14 ms |
23824 KB |
Output is correct |
5 |
Correct |
15 ms |
24104 KB |
Output is correct |
6 |
Correct |
17 ms |
24164 KB |
Output is correct |
7 |
Correct |
16 ms |
24516 KB |
Output is correct |
8 |
Correct |
15 ms |
24140 KB |
Output is correct |
9 |
Correct |
17 ms |
24780 KB |
Output is correct |
10 |
Correct |
17 ms |
24896 KB |
Output is correct |
11 |
Correct |
562 ms |
57604 KB |
Output is correct |
12 |
Correct |
2457 ms |
149804 KB |
Output is correct |
13 |
Correct |
2758 ms |
176092 KB |
Output is correct |
14 |
Correct |
1430 ms |
86568 KB |
Output is correct |
15 |
Correct |
1414 ms |
99804 KB |
Output is correct |
16 |
Correct |
1378 ms |
98000 KB |
Output is correct |
17 |
Correct |
2674 ms |
187100 KB |
Output is correct |
18 |
Correct |
2823 ms |
182844 KB |
Output is correct |
19 |
Correct |
2932 ms |
193620 KB |
Output is correct |
20 |
Correct |
965 ms |
96936 KB |
Output is correct |
21 |
Correct |
22 ms |
24776 KB |
Output is correct |
22 |
Correct |
21 ms |
25604 KB |
Output is correct |
23 |
Correct |
21 ms |
25692 KB |
Output is correct |
24 |
Correct |
20 ms |
25420 KB |
Output is correct |
25 |
Correct |
21 ms |
26644 KB |
Output is correct |
26 |
Correct |
24 ms |
24564 KB |
Output is correct |
27 |
Correct |
24 ms |
25684 KB |
Output is correct |
28 |
Correct |
26 ms |
26864 KB |
Output is correct |
29 |
Correct |
20 ms |
24688 KB |
Output is correct |
30 |
Correct |
23 ms |
25676 KB |
Output is correct |
31 |
Correct |
51 ms |
26572 KB |
Output is correct |
32 |
Correct |
70 ms |
28124 KB |
Output is correct |
33 |
Correct |
66 ms |
29452 KB |
Output is correct |
34 |
Correct |
181 ms |
37520 KB |
Output is correct |
35 |
Correct |
41 ms |
36228 KB |
Output is correct |
36 |
Correct |
133 ms |
38588 KB |
Output is correct |
37 |
Correct |
84 ms |
30220 KB |
Output is correct |
38 |
Correct |
156 ms |
38772 KB |
Output is correct |
39 |
Correct |
95 ms |
38096 KB |
Output is correct |
40 |
Correct |
101 ms |
31128 KB |
Output is correct |
41 |
Correct |
279 ms |
49152 KB |
Output is correct |
42 |
Correct |
1098 ms |
148540 KB |
Output is correct |
43 |
Correct |
439 ms |
139960 KB |
Output is correct |
44 |
Correct |
2036 ms |
179400 KB |
Output is correct |
45 |
Correct |
1821 ms |
175948 KB |
Output is correct |
46 |
Correct |
898 ms |
87544 KB |
Output is correct |
47 |
Correct |
1215 ms |
88800 KB |
Output is correct |
48 |
Correct |
1150 ms |
166760 KB |
Output is correct |
49 |
Correct |
880 ms |
88852 KB |
Output is correct |
50 |
Correct |
945 ms |
88140 KB |
Output is correct |
51 |
Correct |
597 ms |
126532 KB |
Output is correct |
52 |
Correct |
1655 ms |
149096 KB |
Output is correct |
53 |
Correct |
1214 ms |
167208 KB |
Output is correct |
54 |
Correct |
2396 ms |
161252 KB |
Output is correct |
55 |
Correct |
2840 ms |
173796 KB |
Output is correct |