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>
#include "beechtree.h"
using namespace std;
typedef long long ll;
vector<int> beechtree(int n, int m, vector<int> p, vector<int> c) {
vector<int> res(n, 1);
vector<vector<ll>> adj(n);
for (int i = 1; i < n; i++) {
adj[p[i]].push_back(i);
}
vector<pair<ll, ll>> szId(n);
for (int i = 0; i < n; i++) {
szId[i] = {adj[i].size(), i};
}
sort(szId.begin(), szId.end());
unordered_set<ll> used;
if (szId.back().second != 0) res[0] = 0;
for (auto &e : adj[0]) {
if (used.count(c[e]))
res[0] = 0;
used.insert(c[e]);
}
for (int i = n-1; i >= 1; i--) {
unordered_set<ll> nw;
for (auto &e : adj[szId[i].second]) {
if (!used.count(c[e]))
res[0] = 0;
if (nw.count(c[e]))
res[szId[i].second] = res[0] = 0;
nw.insert(c[e]);
}
used = nw;
}
return res;
}
# | 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... |