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;
vector<int> beechtree(int N,int M,vector<int> P,vector<int> C){
vector<int> ans(N);
vector<vector<int>> adj(N);
for(int i=1;i<N;i++)adj[P[i]].emplace_back(i);
auto check = [&](int root){
map<int,int> cnt;
priority_queue<tuple<int,int,int>> q;
vector<int> seq = {root};
for(int&i:adj[root])q.emplace(adj[i].size(),0,i);
while(!q.empty()) {
auto [a,b,curr] = q.top();q.pop();
if(seq[cnt[C[curr]]]!=P[curr])return false;
cnt[C[curr]]++;
seq.emplace_back(curr);
for(int&i:adj[curr])q.emplace(adj[i].size(),-(seq.size()-1),i);
}
return true;
};
for(int i=0;i<=N;i++)if(check(i))ans[i]=1;
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... |