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 "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> piii;
int N, M;
vector<int> adj[202020];
vector<int> P, C;
int cnt[202020];
int idx[202020];
bool solve(int rt) {
for (int i = 1; i <= M; i++) cnt[i] = 0;
int id = 0;
priority_queue<piii> pq;
pq.emplace((int)adj[rt].size(), 0, rt);
while (pq.size()) {
int x = get<2>(pq.top()); pq.pop();
if (x != rt) {
if (cnt[C[x]] != idx[P[x]]) return false;
cnt[C[x]]++;
}
idx[x] = id++;
for (int i : adj[x]) pq.emplace((int)adj[i].size(), -idx[x], i);
}
return true;
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C)
{
::N = N; ::M = M; ::P = P; ::C = C;
vector<int> ans(N);
for (int i = 1; i < N; i++) adj[P[i]].push_back(i);
for (int i = 0; i < N; i++) ans[i] = solve(i);
return ans;
}
# | 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... |