#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
int N;
vector<set<int>> adj;
void init(int k, vector<int> r) {
N = r.size();
adj = vector<set<int>>(N, set<int>());
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]) {
adj[x].insert(*it);
if (*it == y) {
return 1;
}
visited[*it] = true;
q.push(*it);
}
}
}
fill(visited.begin(), visited.end(), false);
q.push(y);
visited[y] = 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]) {
adj[y].insert(*it);
if (*it == x) {
return -1;
}
visited[*it] = true;
q.push(*it);
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
288 KB |
Output is correct |
6 |
Correct |
103 ms |
3196 KB |
Output is correct |
7 |
Execution timed out |
4054 ms |
96632 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
288 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
288 KB |
Output is correct |
6 |
Correct |
103 ms |
3196 KB |
Output is correct |
7 |
Execution timed out |
4054 ms |
96632 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |