# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1066948 | pcc | Beech Tree (IOI23_beechtree) | C++17 | 190 ms | 72364 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 "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fs first
#define sc second
const int mxn = 2e5+10;
vector<pii> tree[mxn];
pii par[mxn];
int dep[mxn];
vector<int> lvl[3];
set<int> st[mxn];
vector<int> ans;
vector<int> col[mxn];
bitset<mxn> active;
pii eul[mxn];
int ptr = 0;
void dfs(int now){
eul[now].fs = ++ptr;
for(auto [nxt,w]:tree[now]){
dfs(nxt);
if(!ans[nxt])ans[now] = 0;
if(st[now].size()<st[nxt].size())st[now].swap(st[nxt]);
for(auto &i:st[nxt])st[now].insert(i);
st[now].insert(w);
}
eul[now].sc = ptr;
if(st[now].size() != tree[now].size())ans[now] = 0;
int tar = -1;
for(auto [nxt,w]:tree[now]){
if(col[w].size()<2)continue;
int now = (col[w][0] == now?col[w][1]:col[w][0]);
if(tar == -1)tar = now;
else if(now != tar)ans[now] = 0;
}
return;
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C){
ans = vector<int>(N,1);
for(int i = 1;i<N;i++){
int p = P[i];
tree[p].push_back(pii(i,C[i]));
par[i] = pii(p,C[i]);
col[C[i]].push_back(p);
}
dfs(0);
return ans;
}
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... |