#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;
for(int&i:adj[x]) {
if(contains[C[i]])return -2;
contains[C[i]]=true;
auto curr = dfs(i);
if(curr==-2)return -2;
if(curr==-1)continue;
if(state!=-1 and state!=curr)return -2;
state=curr;
}
ans[x]=1;
return state;
};
dfs(0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
2nd lines differ - on the 3rd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
2nd lines differ - on the 3rd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
2nd lines differ - on the 3rd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
2nd lines differ - on the 3rd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |