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<bits/stdc++.h>
#include "beechtree.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define pii pair<int,int>
vector<int>beechtree(int n,int m,vector<int>p,vector<int>c){
vector<int>g[n],col[n];
for(int i=1;i<n;i++){
g[p[i]].pb(i);
col[p[i]].pb(c[i]);
}
vector<bool>same(n,false);
for(int i=0;i<n;i++){
sort(all(col[i]));
for(int j=1;j<col[i].size();j++){
if(col[i][j]==col[i][j-1]){
same[j]=true;
}
}
}
vector<int>b(n,0),f(m+1,0);
for(int i=0;i<n;i++){
vector<int>u;
priority_queue<pii,vector<pii>,greater<pii>>q;
q.push({g[i].size(),i});
bool ok=true;
while(!q.empty()){
auto [sz,x]=q.top();
u.pb(x);
if(same[x]){
ok=false;
}
q.pop();
for(int y:g[x]){
q.push({g[y].size(),y});
}
}
if(!ok){
continue;
}
for(int j=1;j<u.size();j++){
if(g[u[j]].size()>g[u[j-1]].size()){
ok=false;
break;
}
int pos=0;
for(int k=0;k<g[u[j]].size();k++){
while(pos<g[u[j-1]].size()&&g[u[j-1]][pos]!=g[u[j]][k]){
pos++;
}
if(pos==g[u[j-1]].size()){
ok=false;
break;
}
pos++;
}
if(!ok){
break;
}
}
if(ok){
b[i]=1;
}
}
return b;
}
Compilation message (stderr)
beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int j=1;j<col[i].size();j++){
| ~^~~~~~~~~~~~~~
beechtree.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int j=1;j<u.size();j++){
| ~^~~~~~~~~
beechtree.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int k=0;k<g[u[j]].size();k++){
| ~^~~~~~~~~~~~~~~
beechtree.cpp:56:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while(pos<g[u[j-1]].size()&&g[u[j-1]][pos]!=g[u[j]][k]){
| ~~~^~~~~~~~~~~~~~~~~
beechtree.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | if(pos==g[u[j-1]].size()){
| ~~~^~~~~~~~~~~~~~~~~~
# | 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... |