// hola soy Dember :D
// 31/03/2024
#include <bits/stdc++.h>
#include "beechtree.h"
#define ll long long
#define pll pair<ll,ll>
#define F first
#define S second
#define Z size()
#define pb push_back
#define bp pop_back
#define fo(x,y,z) for(ll x=y; x<=z; x++)
#define of(x,y,z) for(ll x=y; x>=z; x--)
#define all(n) n.begin(), n.end()
#define arr(x,y,z) x+y, x+y+z
using namespace std;
const int MN=2e5+5;
int n, m;
vector<int> v[MN], p, c, ans;
int a[MN], b[MN];
void CD(int xd=0){
b[xd]=1;
for (int &u: v[xd]){
CD(u);
b[xd]+=b[u];
}
priority_queue<tuple<int, int, int>> q;
q.emplace(b[xd], 0, xd);
vector<int> V;
fo(i,0,m)a[i]=0;
while(!q.empty()){
auto x=get<2>(q.top()); q.pop();
if (x!=xd) {
if (a[c[x]]>=V.size() || V[a[c[x]]]!=p[x])return;
a[c[x]]++;
}
if(x!=xd){
if(a[c[x]]!=b[p[x]])return;
a[c[x]]++;
}
V.push_back(x);
for (int u:v[x])q.emplace(b[u], -V.size(), u);
}
ans[xd]=1;
return;
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C)
{
n=N; m=M; p=P; c=C;ans.resize(n,0);
fo(i,1,n-1)v[p[i]].push_back(i);
CD();
return ans;
}
Compilation message
beechtree.cpp: In function 'void CD(int)':
beechtree.cpp:45:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if (a[c[x]]>=V.size() || V[a[c[x]]]!=p[x])return;
| ~~~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
6492 KB |
2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
6492 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 |
Incorrect |
2 ms |
6492 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
6492 KB |
2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
6492 KB |
2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
2nd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
6492 KB |
2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |