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);
function<int(int)> dfs = [&](int x){
vector<bool> contains(3);
int state = -1;
bool works = true;
for(int&i:adj[x]) {
if(contains[C[i]]) {
works=false;
}
contains[C[i]]=true;
auto curr = dfs(i);
if(curr==-2) {
works = false;
continue;
}
if(curr==-1)continue;
if(state!=-1 and state!=curr) {
works=false;
continue;
}
state=curr;
}
if(contains[1] and !contains[2]) {
if(state==2)return -2;
state=1;
}
if(!contains[1] and contains[2]) {
if(state==1)return -2;
state=2;
}
if(!works)return -2;
ans[x]=1;
return state;
};
dfs(0);
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... |