#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();
adj = vector<set<int>>(N, set<int>());
radj = 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]) {
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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |