#include <bits/stdc++.h>
using namespace std;
const int N1=2e5+100;
int n,m,p[N1],c[N1],cnt[N1];
vector<int> sub[N1],ma[N1];
void dfs(int x)
{
sub[x].clear();
for(int&y:ma[x])
{
dfs(y);
for(int&l:sub[y])sub[x].push_back(l);
sub[x].push_back(y);
}
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C)
{
n=N,m=M;
bool subtask=1;
for(int i=0;i<n;i++)p[i]=P[i],c[i]=C[i],ma[i].clear(),subtask=(subtask&((p[i]==(i-1))));
// if(subtask)
// {
// vector<int> b(n);
// map<int,int> cntp;
// for(int i=n-1;i>=0;i--)
// {
// cntp[c[i]]++;
// if(cntp.size()==1)
// {
// b[i]=1;
// }
// else if(cntp.size()==2 and min(cntp[c[i]],n-cntp[c[i]])==1)
// {
// b[i]=1;
// }
// else{
// b[i]=0;
// }
// }
// return b;
// }
// else
// {
// cout<<"Edges\n";
for(int i=1;i<n;i++)
{
// cout<<p[i]<<' '<<i<<endl;
ma[p[i]].push_back(i);
}
// cout<<"Edges\n";
dfs(0);
vector<int> b(n);
for(int i=0;i<n;i++)
{
// cout<<"COl "<<i<<' '<<c[i]<<endl;
int sz=sub[i].size();
map<int,int> cntp;
int l=-1;
for(int j=0;j<sz;j++)
{
int v=sub[i][j];
cntp[c[v]]++;
l=v;
}
if(cntp.size()==0)
{
b[i]=1;
}
else if(cntp.size()==1)
{
b[i]=1;
}
else if(cntp.size()==2 and min(cntp[c[l]],sz-cntp[c[l]])==1)
{
b[i]=1;
}
else{
b[i]=0;
}
}
return b;
// }
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
10840 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Incorrect |
3 ms |
10844 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 |
2 ms |
10844 KB |
Output is correct |
2 |
Incorrect |
3 ms |
10844 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 |
2 ms |
10844 KB |
2nd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Incorrect |
3 ms |
10844 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 |
2 ms |
10840 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Incorrect |
3 ms |
10844 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 |
2 ms |
10840 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Incorrect |
3 ms |
10844 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 |
2 ms |
10840 KB |
2nd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |