#include <bits/stdc++.h>
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<int>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
int N, P[1000001], C[1000001], S[1000001];
vector<int> adj[1000001], R;
set<int> res;
bool vis[1000001];
int findSet(int v) {
if(P[v] == v) return v;
return P[v] = findSet(P[v]);
}
void unionSet(int u, int v) {
u = findSet(u), v = findSet(v);
if(u == v) return;
P[v] = u; S[u] += S[v];
}
void Init(int n) {
N = n;
for(int l = 0; l < N; l++)
P[l] = l, res.insert(l);
}
void solve(set<int> cur) {
auto it = cur.begin(); set<int> New;
while(it != cur.end()) {
if(res.count(*it))
New.insert(*it);
it++;
}
swap(New, res);
}
bool dfs(int v, int p, int d) {
C[v] = p; vis[v] = 1;
R.push_back(v);
if(v == d) {
set<int> cur;
cur.insert(v); v = C[v];
while(v != d) {
cur.insert(v); v = C[v];
}
solve(cur);
return 1;
}
for(auto u : adj[v]) {
if(u == p || vis[u]) continue;
if(dfs(u, v, d)) return 1;
}
return 0;
}
void Link(int A, int B) {
int U = findSet(A), V = findSet(B);
adj[A].push_back(B);
adj[B].push_back(A);
if(U == V) {
S[U]++;
if(S[U] <= 3) dfs(A, B, B);
for(auto u : R) vis[u] = 0;
R.clear();
if(S[U] == 2) {
set<int> New;
auto it = res.begin();
while(it != res.end()) {
if(adj[*it].size() >= 3)
New.insert(*it);
it++;
}
swap(New, res);
}
}
else unionSet(U, V);
set<int> New;
if(adj[A].size() == 4)
New.clear(), New.insert(A), solve(New);
if(adj[B].size() == 4)
New.clear(), New.insert(B), solve(New);
if(adj[A].size() == 3) {
New.clear(); New.insert(A);
for(auto u : adj[A])
New.insert(u);
solve(New);
}
if(adj[B].size() == 3) {
New.clear(); New.insert(B);
for(auto u : adj[B])
New.insert(u);
solve(New);
}
}
int CountCritical() {
return res.size();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23812 KB |
Output is correct |
2 |
Correct |
13 ms |
24220 KB |
Output is correct |
3 |
Correct |
14 ms |
24148 KB |
Output is correct |
4 |
Correct |
12 ms |
23892 KB |
Output is correct |
5 |
Correct |
15 ms |
24592 KB |
Output is correct |
6 |
Correct |
16 ms |
25440 KB |
Output is correct |
7 |
Correct |
13 ms |
24060 KB |
Output is correct |
8 |
Correct |
15 ms |
24308 KB |
Output is correct |
9 |
Correct |
15 ms |
24248 KB |
Output is correct |
10 |
Correct |
14 ms |
24276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
437 ms |
75540 KB |
Output is correct |
2 |
Correct |
847 ms |
92300 KB |
Output is correct |
3 |
Correct |
1211 ms |
96740 KB |
Output is correct |
4 |
Correct |
1072 ms |
125916 KB |
Output is correct |
5 |
Correct |
1103 ms |
134724 KB |
Output is correct |
6 |
Runtime error |
1484 ms |
262144 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23812 KB |
Output is correct |
2 |
Correct |
13 ms |
24220 KB |
Output is correct |
3 |
Correct |
14 ms |
24148 KB |
Output is correct |
4 |
Correct |
12 ms |
23892 KB |
Output is correct |
5 |
Correct |
15 ms |
24592 KB |
Output is correct |
6 |
Correct |
16 ms |
25440 KB |
Output is correct |
7 |
Correct |
13 ms |
24060 KB |
Output is correct |
8 |
Correct |
15 ms |
24308 KB |
Output is correct |
9 |
Correct |
15 ms |
24248 KB |
Output is correct |
10 |
Correct |
14 ms |
24276 KB |
Output is correct |
11 |
Correct |
14 ms |
24276 KB |
Output is correct |
12 |
Correct |
17 ms |
24996 KB |
Output is correct |
13 |
Correct |
18 ms |
24916 KB |
Output is correct |
14 |
Correct |
17 ms |
24532 KB |
Output is correct |
15 |
Correct |
19 ms |
25044 KB |
Output is correct |
16 |
Correct |
19 ms |
24916 KB |
Output is correct |
17 |
Correct |
18 ms |
24660 KB |
Output is correct |
18 |
Correct |
22 ms |
25076 KB |
Output is correct |
19 |
Correct |
17 ms |
24860 KB |
Output is correct |
20 |
Correct |
18 ms |
24664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23812 KB |
Output is correct |
2 |
Correct |
13 ms |
24220 KB |
Output is correct |
3 |
Correct |
14 ms |
24148 KB |
Output is correct |
4 |
Correct |
12 ms |
23892 KB |
Output is correct |
5 |
Correct |
15 ms |
24592 KB |
Output is correct |
6 |
Correct |
16 ms |
25440 KB |
Output is correct |
7 |
Correct |
13 ms |
24060 KB |
Output is correct |
8 |
Correct |
15 ms |
24308 KB |
Output is correct |
9 |
Correct |
15 ms |
24248 KB |
Output is correct |
10 |
Correct |
14 ms |
24276 KB |
Output is correct |
11 |
Correct |
14 ms |
24276 KB |
Output is correct |
12 |
Correct |
17 ms |
24996 KB |
Output is correct |
13 |
Correct |
18 ms |
24916 KB |
Output is correct |
14 |
Correct |
17 ms |
24532 KB |
Output is correct |
15 |
Correct |
19 ms |
25044 KB |
Output is correct |
16 |
Correct |
19 ms |
24916 KB |
Output is correct |
17 |
Correct |
18 ms |
24660 KB |
Output is correct |
18 |
Correct |
22 ms |
25076 KB |
Output is correct |
19 |
Correct |
17 ms |
24860 KB |
Output is correct |
20 |
Correct |
18 ms |
24664 KB |
Output is correct |
21 |
Correct |
41 ms |
27940 KB |
Output is correct |
22 |
Correct |
53 ms |
30376 KB |
Output is correct |
23 |
Correct |
64 ms |
32076 KB |
Output is correct |
24 |
Correct |
67 ms |
30184 KB |
Output is correct |
25 |
Correct |
43 ms |
29616 KB |
Output is correct |
26 |
Correct |
68 ms |
30668 KB |
Output is correct |
27 |
Correct |
81 ms |
32160 KB |
Output is correct |
28 |
Correct |
62 ms |
30276 KB |
Output is correct |
29 |
Correct |
58 ms |
30148 KB |
Output is correct |
30 |
Correct |
86 ms |
37880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23812 KB |
Output is correct |
2 |
Correct |
13 ms |
24220 KB |
Output is correct |
3 |
Correct |
14 ms |
24148 KB |
Output is correct |
4 |
Correct |
12 ms |
23892 KB |
Output is correct |
5 |
Correct |
15 ms |
24592 KB |
Output is correct |
6 |
Correct |
16 ms |
25440 KB |
Output is correct |
7 |
Correct |
13 ms |
24060 KB |
Output is correct |
8 |
Correct |
15 ms |
24308 KB |
Output is correct |
9 |
Correct |
15 ms |
24248 KB |
Output is correct |
10 |
Correct |
14 ms |
24276 KB |
Output is correct |
11 |
Correct |
437 ms |
75540 KB |
Output is correct |
12 |
Correct |
847 ms |
92300 KB |
Output is correct |
13 |
Correct |
1211 ms |
96740 KB |
Output is correct |
14 |
Correct |
1072 ms |
125916 KB |
Output is correct |
15 |
Correct |
1103 ms |
134724 KB |
Output is correct |
16 |
Runtime error |
1484 ms |
262144 KB |
Execution killed with signal 9 |
17 |
Halted |
0 ms |
0 KB |
- |