# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
940114 | Trisanu_Das | Beech Tree (IOI23_beechtree) | C++17 | 105 ms | 60056 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 pb push_back
#define all(x) x.begin(), x.end()
const int N = 2e5+100;
int sz[N];
vector<array<int, 2>> g[N];
vector<int> ans;
set<int> C[N];
void dfs(int v){
ans[v] = 1;
sz[v] = 1;
for(auto U: g[v]){
int u = U[0], c = U[1];
dfs(u);
sz[v] += sz[u];
ans[v] &= ans[u];
if(C[v].find(c) != C[v].end()) ans[v] = 0;
C[v].insert(c);
}
if(ans[v] == 0) return;
sort(all(g[v]), [&](const array<int, 2> &x, const array<int, 2> &y){
return sz[x[0]] > sz[y[0]];
});
for(int i = 0; i < g[v].size(); ++i){
int x = (i == 0 ? v : g[v][i - 1][0]), y = g[v][i][0];
for(auto col: C[y]){
if(C[x].find(col) == C[x].end()){
ans[v] = 0;
break;
}
}
}
}
vector<int> beechtree(int n, int m, vector<int> P, vector<int> C){
for(int i = 1; i < n; ++i) g[P[i]].pb({i, C[i]});
ans.resize(n);
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... |