#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
using namespace std;
template<typename T1, typename T2>
ostream& operator << (ostream &i, pair<T1, T2> j) {
return i << j.first << ' ' << j.second;
}
template<typename T>
ostream& operator << (ostream &i, vector<T> j) {
i << '{' << j.size() << ':';
for (T ii : j) i << ' ' << ii;
return i << '}';
}
void Debug(bool _split) {}
template<typename T1, typename ...T2>
void Debug(bool _split, T1 x, T2 ...args) {
if (_split)
cerr << ", ";
cerr << x, Debug(true, args...);
}
template<typename T>
void Debuga(T *i, int n) {
cerr << '[';
for (int j = 0; j < n; ++j) cerr << i[j] << " ]"[j == n - 1];
cerr << endl;
}
#ifdef SYL
#define debug(args...) cerr << "Line(" << __LINE__ << ") -> [" << #args << "] is [", Debug(false, args), cerr << ']' << endl
#define debuga(i) cerr << "Line(" << __LINE__ << ") -> [" << #i << "] is ", Debuga(i, sizeof(i) / sizeof(typeid(*i).name()))
#else
#define debug(args...) void(0)
#define debuga(i) void(0)
#endif
typedef long long ll;
typedef pair<int, int> pi;
const int inf = 0x3f3f3f3f, lg = 20;
const ll mod = 1e9 + 7, INF = 0x3f3f3f3f3f3f3f3f;
vector<vector<int>> deg, pa, g;
vector<bool> fail;
vector<int> v, sz, id;
int n, ans;
int extend() {
deg.emplace_back(n, 0);
pa.emplace_back(n);
iota(all(pa.back()), 0);
fail.push_back(false);
assert(deg.size() <= 5);
return deg.size() - 1;
}
int find(int _id, int i) {
return pa[_id][i] = pa[_id][i] == i ? i : find(_id, pa[_id][i]);
}
void upd(vector<int> tmp) {
if (fail[0])
return;
if (v.empty()) {
v = tmp;
return;
}
for (int i = 0; i < (int)v.size(); ) {
bool find = false;
for (int j : tmp)
if (v[i] == j)
find = true;
if (!find)
swap(v[i], v.back()), v.pop_back();
else
++i;
}
if (v.empty())
fail[0] = true;
}
void add(int _id, pi _e) {
if (fail[_id])
return;
int x = _e.first, y = _e.second;
if (++deg[_id][x] >= 3) {
fail[_id] = true;
return;
}
if (++deg[_id][y] >= 3) {
fail[_id] = true;
return;
}
x = find(_id, x), y = find(_id, y);
if (x == y) {
fail[_id] = true;
return;
}
pa[_id][x] = y;
}
vector<pi> e;
void Init(int N) {
ans = n = N;
extend();
g.resize(n);
sz.assign(n, 1);
id.assign(n, -1);
}
void Link(int x, int y) {
if (fail[0])
return;
++deg[0][x], ++deg[0][y];
g[x].push_back(y), g[y].push_back(x);
e.emplace_back(x, y);
if (deg[0][x] == 4) {
vector<int> tmp(1, x);
upd(tmp);
}
else if (deg[0][x] == 3) {
vector<int> tmp = g[x];
tmp.push_back(x);
upd(tmp);
}
if (deg[0][y] == 4) {
vector<int> tmp(1, y);
upd(tmp);
}
else if (deg[0][y] == 3) {
vector<int> tmp = g[y];
tmp.push_back(y);
upd(tmp);
}
x = find(0, x), y = find(0, y);
if (x == y) {
if (!fail[0] && v.empty()) {
if (ans == n)
ans = sz[x];
else
ans = 0;
}
}
else
pa[0][x] = y, sz[y] += sz[x];
}
int CountCritical() {
if (fail[0])
return 0;
if (v.empty())
return ans;
vector<int> tmp;
for (int i : v) {
if (id[i] == -1)
id[i] = extend();
for (pi j : e)
if (j.first != i && j.second != i)
add(id[i], j);
if (!fail[id[i]])
tmp.push_back(i);
}
e.clear();
upd(tmp);
return v.size();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
808 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
3 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
584 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
385 ms |
42716 KB |
Output is correct |
2 |
Correct |
948 ms |
72876 KB |
Output is correct |
3 |
Correct |
190 ms |
45252 KB |
Output is correct |
4 |
Correct |
1046 ms |
83656 KB |
Output is correct |
5 |
Correct |
1061 ms |
83556 KB |
Output is correct |
6 |
Correct |
1004 ms |
82200 KB |
Output is correct |
7 |
Correct |
180 ms |
45228 KB |
Output is correct |
8 |
Correct |
1227 ms |
93264 KB |
Output is correct |
9 |
Correct |
1248 ms |
91296 KB |
Output is correct |
10 |
Correct |
725 ms |
81840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
808 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
3 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
584 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
3 ms |
844 KB |
Output is correct |
12 |
Correct |
5 ms |
1484 KB |
Output is correct |
13 |
Correct |
5 ms |
1484 KB |
Output is correct |
14 |
Correct |
3 ms |
972 KB |
Output is correct |
15 |
Correct |
4 ms |
1484 KB |
Output is correct |
16 |
Correct |
4 ms |
1160 KB |
Output is correct |
17 |
Correct |
2 ms |
844 KB |
Output is correct |
18 |
Correct |
3 ms |
1292 KB |
Output is correct |
19 |
Correct |
6 ms |
1228 KB |
Output is correct |
20 |
Correct |
5 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
808 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
3 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
584 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
3 ms |
844 KB |
Output is correct |
12 |
Correct |
5 ms |
1484 KB |
Output is correct |
13 |
Correct |
5 ms |
1484 KB |
Output is correct |
14 |
Correct |
3 ms |
972 KB |
Output is correct |
15 |
Correct |
4 ms |
1484 KB |
Output is correct |
16 |
Correct |
4 ms |
1160 KB |
Output is correct |
17 |
Correct |
2 ms |
844 KB |
Output is correct |
18 |
Correct |
3 ms |
1292 KB |
Output is correct |
19 |
Correct |
6 ms |
1228 KB |
Output is correct |
20 |
Correct |
5 ms |
1484 KB |
Output is correct |
21 |
Correct |
15 ms |
3852 KB |
Output is correct |
22 |
Correct |
24 ms |
5908 KB |
Output is correct |
23 |
Correct |
33 ms |
7388 KB |
Output is correct |
24 |
Correct |
43 ms |
6932 KB |
Output is correct |
25 |
Correct |
16 ms |
7844 KB |
Output is correct |
26 |
Correct |
43 ms |
9992 KB |
Output is correct |
27 |
Correct |
37 ms |
7884 KB |
Output is correct |
28 |
Correct |
21 ms |
7756 KB |
Output is correct |
29 |
Correct |
22 ms |
8268 KB |
Output is correct |
30 |
Correct |
47 ms |
9144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
808 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
3 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
584 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
385 ms |
42716 KB |
Output is correct |
12 |
Correct |
948 ms |
72876 KB |
Output is correct |
13 |
Correct |
190 ms |
45252 KB |
Output is correct |
14 |
Correct |
1046 ms |
83656 KB |
Output is correct |
15 |
Correct |
1061 ms |
83556 KB |
Output is correct |
16 |
Correct |
1004 ms |
82200 KB |
Output is correct |
17 |
Correct |
180 ms |
45228 KB |
Output is correct |
18 |
Correct |
1227 ms |
93264 KB |
Output is correct |
19 |
Correct |
1248 ms |
91296 KB |
Output is correct |
20 |
Correct |
725 ms |
81840 KB |
Output is correct |
21 |
Correct |
3 ms |
844 KB |
Output is correct |
22 |
Correct |
5 ms |
1484 KB |
Output is correct |
23 |
Correct |
5 ms |
1484 KB |
Output is correct |
24 |
Correct |
3 ms |
972 KB |
Output is correct |
25 |
Correct |
4 ms |
1484 KB |
Output is correct |
26 |
Correct |
4 ms |
1160 KB |
Output is correct |
27 |
Correct |
2 ms |
844 KB |
Output is correct |
28 |
Correct |
3 ms |
1292 KB |
Output is correct |
29 |
Correct |
6 ms |
1228 KB |
Output is correct |
30 |
Correct |
5 ms |
1484 KB |
Output is correct |
31 |
Correct |
15 ms |
3852 KB |
Output is correct |
32 |
Correct |
24 ms |
5908 KB |
Output is correct |
33 |
Correct |
33 ms |
7388 KB |
Output is correct |
34 |
Correct |
43 ms |
6932 KB |
Output is correct |
35 |
Correct |
16 ms |
7844 KB |
Output is correct |
36 |
Correct |
43 ms |
9992 KB |
Output is correct |
37 |
Correct |
37 ms |
7884 KB |
Output is correct |
38 |
Correct |
21 ms |
7756 KB |
Output is correct |
39 |
Correct |
22 ms |
8268 KB |
Output is correct |
40 |
Correct |
47 ms |
9144 KB |
Output is correct |
41 |
Correct |
190 ms |
33528 KB |
Output is correct |
42 |
Correct |
595 ms |
84988 KB |
Output is correct |
43 |
Correct |
292 ms |
72516 KB |
Output is correct |
44 |
Correct |
192 ms |
77864 KB |
Output is correct |
45 |
Correct |
417 ms |
84660 KB |
Output is correct |
46 |
Correct |
652 ms |
76576 KB |
Output is correct |
47 |
Correct |
869 ms |
78160 KB |
Output is correct |
48 |
Correct |
225 ms |
79392 KB |
Output is correct |
49 |
Correct |
637 ms |
80840 KB |
Output is correct |
50 |
Correct |
675 ms |
80084 KB |
Output is correct |
51 |
Correct |
316 ms |
64952 KB |
Output is correct |
52 |
Correct |
188 ms |
62976 KB |
Output is correct |
53 |
Correct |
223 ms |
78376 KB |
Output is correct |
54 |
Correct |
1161 ms |
96948 KB |
Output is correct |
55 |
Correct |
1141 ms |
102196 KB |
Output is correct |