#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
struct Dsu {
vector<int> s, p;
Dsu(int n){
s.resize(n+1, 1);
p.resize(n+1);
for(int i = 0; i <= n; ++i) p[i] = i;
}
int find(int v){
if(p[v] == v) return v;
return (p[v] = find(p[v]));
}
void merge(int a, int b){
a = find(a);
b = find(b);
if(a != b){
if(s[a] > s[b]){
swap(a, b);
}
s[b] += s[a];
p[a] = b;
}
}
} d(N), d1(N);
vector<int> v, w(N, -1);
int nn;
void init(int k, vector<int> r){
int n = r.size();
nn =n ;
v = r;
for(int i = 0; i < n; ++i){
if(r[i] == 1){
d.merge(i, (i + 1)%n);
}else{
d1.merge(i, (i + 1)%n);
}
}
int c = 0;
for(int i = 0; i < n; ++i) c += (r[i] != r[(i + 1)%n]);
if(c == 2){
for(int i = 0; i < n; ++i){
if(r[i] != r[(i+1)%n]){
if(r[(i+1)%n] == 1){
w[(i+1)%n] = n;
}else{
w[(i+1)%n] = 1;
}
}
}
}
}
int compare_plants(int x, int y){
if(w[x] == nn || w[y] == 1){
return 1;
}
if(w[y] == nn || w[x] == 1){
return -1;
}
if(d.find(x) == d.find(y)){
return 1;
}else if(d1.find(x) == d1.find(y)){
return -1;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
19796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
19796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
19796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
19796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
19796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
19796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
19796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |