# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1008696 | 2024-06-26T16:46:04 Z | aaaaaarroz | Beech Tree (IOI23_beechtree) | C++17 | 0 ms | 0 KB |
#include "beechtree.h" #include <bits/stdc++.h> using namespace std; vector<int>padre; vector<vector<int>>graph; vector<int>sub; void dfs(int nodo){ sub.push_back(nodo); for(int vecino:graph[nodo]){ dfs(vecino); } } vector<int> beechtree(int n, int m, vector<int>P, vector<int>C){ padre=P; graph.resize(n,vector<int>()); for(int i=0;i<n;i++){ if(P[i]!=-1){ graph[P[i]].push_back(i); } } vector<int>ans; for(int i=0;i<n;i++){ sub.clear(); dfs(i); if(sub.size()==1){ ans.push_back(1); continue; } bool posible=false; do{ bool bien=true; map<int,int>repeticiones; for(int i=1;i<sub.size();i++){ if(repeticiones.find(C[sub[j]])==repeticiones.end()){ repeticiones[C[sub[j]]]=0; } if(repeticiones[C[sub[i]]]!=P[sub[i]]){ bien=false; break; } repeticiones[C[sub[i]]]++; } posible|=bien; }while(next_permutation(sub.begin()+1,sub.end())); ans.push_back((posible==true?1:0)); } return ans; }