#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<int> deg, rt, stk, ring;
vector<int> v;
vector<vector<int>> g;
vector<bool> vis;
bool fail, first;
int n;
int find(int i) {
return rt[i] = rt[i] == i ? i : find(rt[i]);
}
void dfs(int i, int p) {
vis[i] = true;
stk.push_back(i);
for (int j : g[i])
if (j != p) {
if (!vis[j])
dfs(j, i);
else {
while (stk.back() != j)
ring.push_back(stk.back()), stk.pop_back();
ring.push_back(j);
return;
}
if (!ring.empty())
return;
}
stk.pop_back();
}
void upd(vector<int> tmp) {
if (fail)
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 = true;
}
void Init(int N) {
deg.assign(N, 0);
rt.resize(N);
iota(all(rt), 0);
vis.assign(N, false);
g.assign(N, vector<int>());
fail = false, first = true;
n = N;
}
void Link(int x, int y) {
if (fail)
return;
++deg[x], ++deg[y];
g[x].push_back(y), g[y].push_back(x);
if (deg[x] == 4) {
vector<int> tmp(1, x);
upd(tmp);
}
else if (deg[x] == 3) {
vector<int> tmp = g[x];
tmp.push_back(x);
upd(tmp);
}
if (fail)
return;
if (deg[y] == 4) {
vector<int> tmp(1, y);
upd(tmp);
}
else if (deg[y] == 3) {
vector<int> tmp = g[y];
tmp.push_back(y);
upd(tmp);
}
if (fail)
return;
if (find(x) == find(y)) {
if (first) {
first = false;
dfs(x, -1);
debug(ring);
upd(ring);
}
else if (!v.empty() && find(v.back()) != find(x))
fail = true;
}
else {
rt[find(x)] = find(y);
}
}
int CountCritical() {
if (fail)
return 0;
if (v.empty())
return n;
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 |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
369 ms |
33008 KB |
Output is correct |
2 |
Correct |
664 ms |
50480 KB |
Output is correct |
3 |
Correct |
182 ms |
32332 KB |
Output is correct |
4 |
Correct |
862 ms |
62968 KB |
Output is correct |
5 |
Correct |
983 ms |
64904 KB |
Output is correct |
6 |
Correct |
972 ms |
107556 KB |
Output is correct |
7 |
Correct |
163 ms |
32332 KB |
Output is correct |
8 |
Correct |
842 ms |
59020 KB |
Output is correct |
9 |
Correct |
911 ms |
62860 KB |
Output is correct |
10 |
Correct |
573 ms |
61412 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 |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Incorrect |
2 ms |
664 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Incorrect |
2 ms |
664 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
369 ms |
33008 KB |
Output is correct |
12 |
Correct |
664 ms |
50480 KB |
Output is correct |
13 |
Correct |
182 ms |
32332 KB |
Output is correct |
14 |
Correct |
862 ms |
62968 KB |
Output is correct |
15 |
Correct |
983 ms |
64904 KB |
Output is correct |
16 |
Correct |
972 ms |
107556 KB |
Output is correct |
17 |
Correct |
163 ms |
32332 KB |
Output is correct |
18 |
Correct |
842 ms |
59020 KB |
Output is correct |
19 |
Correct |
911 ms |
62860 KB |
Output is correct |
20 |
Correct |
573 ms |
61412 KB |
Output is correct |
21 |
Incorrect |
2 ms |
664 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |