# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
995457 | irmuun | Beech Tree (IOI23_beechtree) | C++17 | 2061 ms | 31536 KiB |
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()
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[i]=true;
}
}
}
vector<int>b(n,0),f(m+1,0);
for(int i=0;i<n;i++){
vector<int>u;
priority_queue<pair<int,int>>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<col[u[j]].size();k++){
while(pos<col[u[j-1]].size()&&col[u[j-1]][pos]!=col[u[j]][k]){
pos++;
}
if(pos==col[u[j-1]].size()){
ok=false;
break;
}
pos++;
}
if(!ok){
break;
}
}
if(ok){
b[i]=1;
}
}
return b;
}
Compilation message (stderr)
# | 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... |