# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031475 | 2024-07-22T21:27:43 Z | aaaaaarroz | Beech Tree (IOI23_beechtree) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; vector<int> padre; vector<int> cc; bool menor_padre(int i, int j){ return cc[i] < cc[j]; } vector<int> beechtree(int n, int m, vector<int>P, vector<int>C){ vector<vector<int>> graph(n,vector<int>()); padre = P; cc=C; for(int i = 1; i < n; i++){ graph[P[i]].push_back(i); } vector<int> ans(n, 0); for(int i = 0; i < n; i++){ vector<int> sub; queue<int> cola; cola.push(i); while(!cola.empty()){ int nodo = cola.front(); cola.pop(); sub.push_back(nodo); for(int vecino : graph[nodo]){ cola.push(vecino); } } if(sub.size() == 1){ ans[i] = 1; continue; } sort(sub.begin() + 1, sub.end(), ); bool bien = true; map<int, int> repeticiones; for(int j = 1; j < sub.size(); j++){ int color = C[sub[j]]; if(repeticiones.find(color) == repeticiones.end()){ repeticiones[color] = 0; } int expected_parent = sub[repeticiones[color]]; if(P[sub[j]] != expected_parent){ bien = false; break; } repeticiones[color]++; } if(bien){ ans[i] = 1; } } return ans; }