#include <bits/stdc++.h>
using namespace std;
int N;
int p[1000005];
int cyc = 0;
set<int> adj[1000005];
set<int> pos, t;
int find(int v){
if(v == p[v]) return v;
return p[v] = find(p[v]);
}
bool merge(int v, int u){
v = find(v);
u = find(u);
if(v == u) return 1;
p[v] = u;
return 0;
}
void Init(int N_) {
N = N_;
for(int i = 0; i < N; i++){
p[i] = i;
pos.insert(i);
}
}
bool in[1000005];
int lol, q;
int dfs(int v){
if(pos.count(v))
t.insert(v);
if(lol != v && adj[v].count(q)){
return 1;
}
for(int x : adj[v]){
if(!in[x]){
in[x] = 1;
if(dfs(x) == 1) return 1;
}
}
if(t.count(v))
t.erase(v);
return 0;
}
void Link(int v, int u) {
if(pos.empty()) return;
adj[v].insert(u);
adj[u].insert(v);
if(adj[v].size() > 3){
if(pos.count(v)){
pos = {v};
} else {
pos.clear();
}
} else if(adj[v].size() == 3){
for(int x : adj[v]){
if(pos.count(x)) t.insert(x);
}
if(pos.count(v)) t.insert(v);
swap(pos, t);
t.clear();
}
if(adj[u].size() > 3){
if(pos.count(u)){
pos = {u};
} else {
pos.clear();
}
} else if(adj[u].size() == 3){
for(int x : adj[u]){
if(pos.count(x)) t.insert(x);
}
if(pos.count(u)) t.insert(u);
swap(pos, t);
t.clear();
}
if(merge(v, u) == 0) return;
cyc++;
if(cyc >= 3){
pos.clear();
return;
}
memset(in, 0, sizeof in);
if(pos.count(v))
t.insert(v);
if(pos.count(u))
t.insert(u);
lol = u;
q = v;
in[v] = 1;
in[u] = 1;
dfs(u);
swap(t, pos);
t.clear();
}
int CountCritical() {
return pos.size();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
47352 KB |
Output is correct |
2 |
Correct |
44 ms |
47736 KB |
Output is correct |
3 |
Correct |
46 ms |
47864 KB |
Output is correct |
4 |
Correct |
42 ms |
48384 KB |
Output is correct |
5 |
Correct |
45 ms |
49016 KB |
Output is correct |
6 |
Correct |
47 ms |
49408 KB |
Output is correct |
7 |
Correct |
41 ms |
47608 KB |
Output is correct |
8 |
Correct |
45 ms |
49144 KB |
Output is correct |
9 |
Correct |
45 ms |
47864 KB |
Output is correct |
10 |
Correct |
44 ms |
47864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
767 ms |
129292 KB |
Output is correct |
2 |
Correct |
1511 ms |
136196 KB |
Output is correct |
3 |
Correct |
595 ms |
111736 KB |
Output is correct |
4 |
Correct |
1833 ms |
206340 KB |
Output is correct |
5 |
Correct |
2033 ms |
208368 KB |
Output is correct |
6 |
Correct |
3608 ms |
248560 KB |
Output is correct |
7 |
Correct |
580 ms |
111096 KB |
Output is correct |
8 |
Correct |
1719 ms |
167548 KB |
Output is correct |
9 |
Correct |
1891 ms |
189648 KB |
Output is correct |
10 |
Correct |
1359 ms |
200696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
47352 KB |
Output is correct |
2 |
Correct |
44 ms |
47736 KB |
Output is correct |
3 |
Correct |
46 ms |
47864 KB |
Output is correct |
4 |
Correct |
42 ms |
48384 KB |
Output is correct |
5 |
Correct |
45 ms |
49016 KB |
Output is correct |
6 |
Correct |
47 ms |
49408 KB |
Output is correct |
7 |
Correct |
41 ms |
47608 KB |
Output is correct |
8 |
Correct |
45 ms |
49144 KB |
Output is correct |
9 |
Correct |
45 ms |
47864 KB |
Output is correct |
10 |
Correct |
44 ms |
47864 KB |
Output is correct |
11 |
Correct |
48 ms |
48760 KB |
Output is correct |
12 |
Correct |
62 ms |
49764 KB |
Output is correct |
13 |
Correct |
53 ms |
49500 KB |
Output is correct |
14 |
Incorrect |
49 ms |
48888 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
47352 KB |
Output is correct |
2 |
Correct |
44 ms |
47736 KB |
Output is correct |
3 |
Correct |
46 ms |
47864 KB |
Output is correct |
4 |
Correct |
42 ms |
48384 KB |
Output is correct |
5 |
Correct |
45 ms |
49016 KB |
Output is correct |
6 |
Correct |
47 ms |
49408 KB |
Output is correct |
7 |
Correct |
41 ms |
47608 KB |
Output is correct |
8 |
Correct |
45 ms |
49144 KB |
Output is correct |
9 |
Correct |
45 ms |
47864 KB |
Output is correct |
10 |
Correct |
44 ms |
47864 KB |
Output is correct |
11 |
Correct |
48 ms |
48760 KB |
Output is correct |
12 |
Correct |
62 ms |
49764 KB |
Output is correct |
13 |
Correct |
53 ms |
49500 KB |
Output is correct |
14 |
Incorrect |
49 ms |
48888 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
47352 KB |
Output is correct |
2 |
Correct |
44 ms |
47736 KB |
Output is correct |
3 |
Correct |
46 ms |
47864 KB |
Output is correct |
4 |
Correct |
42 ms |
48384 KB |
Output is correct |
5 |
Correct |
45 ms |
49016 KB |
Output is correct |
6 |
Correct |
47 ms |
49408 KB |
Output is correct |
7 |
Correct |
41 ms |
47608 KB |
Output is correct |
8 |
Correct |
45 ms |
49144 KB |
Output is correct |
9 |
Correct |
45 ms |
47864 KB |
Output is correct |
10 |
Correct |
44 ms |
47864 KB |
Output is correct |
11 |
Correct |
767 ms |
129292 KB |
Output is correct |
12 |
Correct |
1511 ms |
136196 KB |
Output is correct |
13 |
Correct |
595 ms |
111736 KB |
Output is correct |
14 |
Correct |
1833 ms |
206340 KB |
Output is correct |
15 |
Correct |
2033 ms |
208368 KB |
Output is correct |
16 |
Correct |
3608 ms |
248560 KB |
Output is correct |
17 |
Correct |
580 ms |
111096 KB |
Output is correct |
18 |
Correct |
1719 ms |
167548 KB |
Output is correct |
19 |
Correct |
1891 ms |
189648 KB |
Output is correct |
20 |
Correct |
1359 ms |
200696 KB |
Output is correct |
21 |
Correct |
48 ms |
48760 KB |
Output is correct |
22 |
Correct |
62 ms |
49764 KB |
Output is correct |
23 |
Correct |
53 ms |
49500 KB |
Output is correct |
24 |
Incorrect |
49 ms |
48888 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |