Submission #1241409

#TimeUsernameProblemLanguageResultExecution timeMemory
1241409dostsBeech Tree (IOI23_beechtree)C++20
0 / 100
5 ms7240 KiB
#include "beechtree.h" #include <bits/stdc++.h> //#define int long long #define pii pair<int,int> #define vi vector<int> #define ff first #define ss second #define sp << " " << #define all(x) x.begin(),x.end() using namespace std; const int LIM = 2e5+1; vector<pii> edges[LIM]; vi ans(LIM,0),C,P; int N; vi ctr(LIM,0); vi tot(LIM,0); bool check(int node) { if (edges[node].empty()) return true; if (!node) { int ct =0; for (auto it : edges[node]) { if (ctr[it.ss]) return false; ctr[it.ss]++; ++ct; } for (int i = 0;i<N;i++) if (tot[i]) ct--; return (!ct); } int ct = 0; for (auto it : edges[node]) { if (ctr[it.ss] != 2) return false; ++ct; } for (int i = 0;i<N;i++) if (tot[i]>=2) ct--; return (!ct); } int dfs(int node) { for (auto it : edges[node]) dfs(it.ff); return ans[node] = check(node); } std::vector<int> beechtree(int N_, int M, std::vector<int> P_, std::vector<int> C_) { N = N_; P = P_,C = C_; ans.assign(N_,0); for (int i = 0;i<N;i++) edges[i].clear(),tot[i] = 0; vi v; for (auto it : C) v.push_back(it); sort(all(v)); v.erase(unique(all(v)),v.end()); for (auto& it : C) it = lower_bound(all(v),it)-v.begin(); for (auto it : C) tot[it]++; for (int i = 1;i<N;i++) { edges[P[i]].push_back({i,C[i]}); } dfs(0); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...