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;
using piii = tuple<int, int, int>;
vector<int> T[202020];
vector<int> P, C;
int S[202020], K[202020];
int n, m;
void dfs(int u, vector<int> &A) {
S[u] = 1;
for (int &v: T[u]) {
dfs(v, A);
S[u] += S[v];
}
priority_queue<piii> Q;
vector<int> V;
fill(K, K + m + 1, 0);
Q.emplace(S[u], 0, u);
for (; !Q.empty(); ) {
auto [_, __, v] = Q.top();
Q.pop();
if (v != u) {
if (K[C[v]] >= V.size() || V[K[C[v]]] != P[v]) return;
K[C[v]]++;
}
V.push_back(v);
for (int &w: T[v]) {
Q.emplace(S[w], -V.size(), w);
}
}
A[u] = 1;
}
vector<int> beechtree(int n, int m, vector<int> P, vector<int> C) {
::C = C; ::P = P; ::n = n; ::m = m;
int i;
for (i = 1; i < n; i++) {
T[P[i]].push_back(i);
}
vector<int> A(n);
dfs(0, A);
return A;
}
Compilation message (stderr)
beechtree.cpp: In function 'void dfs(int, std::vector<int>&)':
beechtree.cpp:30:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if (K[C[v]] >= V.size() || V[K[C[v]]] != P[v]) return;
| ~~~~~~~~^~~~~~~~~~~
# | 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... |