#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
vector<pair<int, int> > con;
vector<int> adj[1000005];
set<int> pos, t;
int N;
int p[1000005][3];
void Init(int N_) {
N = N_;
for(int i = 0; i < N; i++)
for(int j = 0; j < 3; j++)
p[i][j] = i;
for(int i = 0; i < N; i++)
pos.insert(i);
}
int put = 0;
int v[3];
int find(int v, int i){
if(v == p[v][i]) return v;
return p[v][i] = find(p[v][i], i);
}
bool merge(int v, int u, int i){
if(i){
if(v == ::v[i]) return 0;
if(u == ::v[i]) return 0;
}
v = find(v, i);
u = find(u, i);
if(v == u) return 1;
p[v][i] = u;
return 0;
}
bool dfs(int A, int B){
t.insert(A);
for(int x : adj[A]){
if(x == B) continue;
if(t.count(x)) return 1;
if(dfs(x, A)) return 1;
}
t.erase(A);
return 0;
}
void Link(int A, int B){
if(pos.empty()) return;
adj[A].push_back(B);
adj[B].push_back(A);
t.clear();
if(adj[A].size() == 4){
if(pos.count(A))
t.insert(A);
swap(t, pos);
t.clear();
} else if(adj[A].size() == 3){
if(pos.count(A))
t.insert(A);
for(int x : adj[A])
if(pos.count(x))
t.insert(x);
swap(t, pos);
t.clear();
}
if(adj[B].size() == 4){
if(pos.count(B))
t.insert(B);
swap(t, pos);
t.clear();
} else if(adj[B].size() == 3){
if(pos.count(B))
t.insert(B);
for(int x : adj[B])
if(pos.count(x))
t.insert(x);
swap(t, pos);
t.clear();
}
if(put == 0 && pos.size() <= 2){
for(int x : pos){
v[++put] = x;
}
for(auto x : con){
if(merge(x.ff, x.ss, 1)) v[1] = -1;
if(merge(x.ff, x.ss, 2)) v[2] = -1;
}
}
con.push_back({A, B});
if(put){
t.clear();
if(merge(A, B, 1)) v[1] = -1;
if(merge(A, B, 2)) v[2] = -1;
if(pos.count(v[1])) t.insert(v[1]);
if(pos.count(v[2])) t.insert(v[2]);
swap(t, pos);
t.clear();
return;
}
if(pos.empty()) return;
if(merge(A, B, 0) == 0 || put) return;
dfs(A, B);
set<int> lol;
for(int x : t)
if(pos.count(x))
lol.insert(x);
swap(lol, pos);
t.clear();
}
int CountCritical() {
return pos.size();
}
Compilation message
rings.cpp: In function 'void Init(int)':
rings.cpp:13:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(int i = 0; i < N; i++)
^~~
rings.cpp:16:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(int i = 0; i < N; i++)
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
23808 KB |
Output is correct |
2 |
Correct |
24 ms |
24220 KB |
Output is correct |
3 |
Correct |
25 ms |
24192 KB |
Output is correct |
4 |
Correct |
21 ms |
23936 KB |
Output is correct |
5 |
Correct |
23 ms |
24320 KB |
Output is correct |
6 |
Correct |
27 ms |
24832 KB |
Output is correct |
7 |
Correct |
22 ms |
24064 KB |
Output is correct |
8 |
Correct |
38 ms |
24440 KB |
Output is correct |
9 |
Correct |
25 ms |
24192 KB |
Output is correct |
10 |
Correct |
25 ms |
24320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
636 ms |
74748 KB |
Output is correct |
2 |
Correct |
1829 ms |
89012 KB |
Output is correct |
3 |
Correct |
673 ms |
83060 KB |
Output is correct |
4 |
Correct |
1698 ms |
121700 KB |
Output is correct |
5 |
Correct |
1708 ms |
124432 KB |
Output is correct |
6 |
Correct |
2765 ms |
188488 KB |
Output is correct |
7 |
Correct |
617 ms |
83340 KB |
Output is correct |
8 |
Correct |
1732 ms |
112652 KB |
Output is correct |
9 |
Correct |
1835 ms |
120820 KB |
Output is correct |
10 |
Correct |
1194 ms |
119720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
23808 KB |
Output is correct |
2 |
Correct |
24 ms |
24220 KB |
Output is correct |
3 |
Correct |
25 ms |
24192 KB |
Output is correct |
4 |
Correct |
21 ms |
23936 KB |
Output is correct |
5 |
Correct |
23 ms |
24320 KB |
Output is correct |
6 |
Correct |
27 ms |
24832 KB |
Output is correct |
7 |
Correct |
22 ms |
24064 KB |
Output is correct |
8 |
Correct |
38 ms |
24440 KB |
Output is correct |
9 |
Correct |
25 ms |
24192 KB |
Output is correct |
10 |
Correct |
25 ms |
24320 KB |
Output is correct |
11 |
Incorrect |
23 ms |
24320 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
23808 KB |
Output is correct |
2 |
Correct |
24 ms |
24220 KB |
Output is correct |
3 |
Correct |
25 ms |
24192 KB |
Output is correct |
4 |
Correct |
21 ms |
23936 KB |
Output is correct |
5 |
Correct |
23 ms |
24320 KB |
Output is correct |
6 |
Correct |
27 ms |
24832 KB |
Output is correct |
7 |
Correct |
22 ms |
24064 KB |
Output is correct |
8 |
Correct |
38 ms |
24440 KB |
Output is correct |
9 |
Correct |
25 ms |
24192 KB |
Output is correct |
10 |
Correct |
25 ms |
24320 KB |
Output is correct |
11 |
Incorrect |
23 ms |
24320 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
23808 KB |
Output is correct |
2 |
Correct |
24 ms |
24220 KB |
Output is correct |
3 |
Correct |
25 ms |
24192 KB |
Output is correct |
4 |
Correct |
21 ms |
23936 KB |
Output is correct |
5 |
Correct |
23 ms |
24320 KB |
Output is correct |
6 |
Correct |
27 ms |
24832 KB |
Output is correct |
7 |
Correct |
22 ms |
24064 KB |
Output is correct |
8 |
Correct |
38 ms |
24440 KB |
Output is correct |
9 |
Correct |
25 ms |
24192 KB |
Output is correct |
10 |
Correct |
25 ms |
24320 KB |
Output is correct |
11 |
Correct |
636 ms |
74748 KB |
Output is correct |
12 |
Correct |
1829 ms |
89012 KB |
Output is correct |
13 |
Correct |
673 ms |
83060 KB |
Output is correct |
14 |
Correct |
1698 ms |
121700 KB |
Output is correct |
15 |
Correct |
1708 ms |
124432 KB |
Output is correct |
16 |
Correct |
2765 ms |
188488 KB |
Output is correct |
17 |
Correct |
617 ms |
83340 KB |
Output is correct |
18 |
Correct |
1732 ms |
112652 KB |
Output is correct |
19 |
Correct |
1835 ms |
120820 KB |
Output is correct |
20 |
Correct |
1194 ms |
119720 KB |
Output is correct |
21 |
Incorrect |
23 ms |
24320 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |