#include <bits/stdc++.h>
#include "plants.h"
using namespace std;
const int MAX_N = 2e5 + 5;
int N, K;
vector <int> R;
int indegree[MAX_N];
vector <int> graph[MAX_N];
int pos[MAX_N];
void dfs(int u, int p) {
pos[u] = p;
for(auto v : graph[u]) {
dfs(v, p + 1);
}
}
void init(int k, vector <int> r) {
K = k, R = r, N = R.size();
for(int i = 0; i < N; i++) {
if(R[i] == 0) {
graph[i + 1].push_back(i);
indegree[i]++;
}
else {
graph[i].push_back(i + 1);
indegree[i + 1]++;
}
}
for(int i = 0; i < N; i++) {
if(indegree[i] == 0) {
dfs(i, 0);
}
}
}
int compare_plants(int x, int y) {
if(pos[x] > pos[y]) {
return 1;
}
if(pos[x] < pos[y]) {
return -1;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4976 KB |
Output is correct |
2 |
Incorrect |
3 ms |
5020 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |