#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
int N;
vector<set<int>> adj, radj;
void init(int k, vector<int> r) {
N = r.size();
for (int i=0; i<N; ++i) {
int u = i, v = (i+1) % N;
if (r[u] == 0) {
adj[u].insert(v);
} else {
adj[v].insert(u);
}
}
}
int compare_plants(int x, int y) {
vector<bool> visited(N);
queue<int> q;
q.push(x);
visited[x] = true;
while (q.size() > 0) {
int cur = q.front(); q.pop();
for (auto it=adj[cur].begin(); it!=adj[cur].end(); ++it) {
if (!visited[*it]) {
if (*it == y) {
return 1;
}
visited[*it] = true;
q.push(*it);
}
}
}
fill(visited.begin(), visited.end(), false);
q.push(x);
visited[x] = true;
while (q.size() > 0) {
int cur = q.front(); q.pop();
for (auto it=radj[cur].begin(); it!=radj[cur].end(); ++it) {
if (!visited[*it]) {
if (*it == y) {
return -1;
}
visited[*it] = true;
q.push(*it);
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |