# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031570 | aaaaaarroz | 참나무 (IOI23_beechtree) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<int> beechtree(int n, int m, vector<int> P, vector<int> C) {
vector<vector<int>> graph(n);
for (int i = 1; i < n; ++i) {
graph[P[i]].push_back(i);
}
vector<int> ans(n, 0);
for (int i = 0; i < n; ++i) {
vector<int> subtree;
stack<int> s;
s.push(i);
while (!s.empty()) {
int node = s.top(); s.pop();
subtree.push_back(node);
for (int neighbor : graph[node]) {
s.push(neighbor);
}
}
sort(subtree.begin() + 1, subtree.end(), [&](int a, int b) {
if (C[a] != C[b]) {
return C[a] < C[b];
}
return a > b;
});
bool is_bonito = true;
for (int j = 1; j < subtree.size(); ++j) {
if (P[subtree[j]] != subtree[j - 1]) {
is_bonito = false;
break;
}
}
ans[i] = is_bonito ? 1 : 0;
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |