This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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+1)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]]++;
}
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]].pb(i);
CD();
return ans;
}
Compilation message (stderr)
beechtree.cpp: In function 'void CD(int)':
beechtree.cpp:45:23: 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 |
---|
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... |