Submission #987427

#TimeUsernameProblemLanguageResultExecution timeMemory
987427activedeltorreBeech Tree (IOI23_beechtree)C++17
0 / 100
2028 ms62304 KiB
#include "beechtree.h" #include <vector> #include <queue> #include <iostream> #include <map> #include <algorithm> using namespace std; vector<int>cop[200005]; int cul[200005]; int imp[200005]; int dist[200005]; int par[200005]; vector<int>vecus; map<int,int>mp; map<int,int>mp2; map<int,int>fre; long long mod=1e9+7; long long has[200005]; vector<long long> vactoriceanu[510]; int nmax=500; int calc(int curr) { mp2.clear(); fre.clear(); int cur; queue<int>qu; dist[curr]=0; qu.push(curr); vecus.clear(); for(int i=1;i<=nmax;i++) { vactoriceanu[i].clear(); } while(qu.size()) { cur=qu.front(); vecus.push_back(cur); qu.pop(); for(auto k:cop[cur]) { dist[k]=dist[curr]+1; qu.push(k); } } int posible=0; for(auto i:vecus) { if(i!=curr) { fre[cul[i]]++; vactoriceanu[fre[cul[i]]].push_back(cul[i]); } mp2[has[i]]++; posible=max(posible,imp[i]); } for(int i=1;i<=nmax;i++) { sort(vactoriceanu[i].begin(),vactoriceanu[i].end()); long long val=0; for(auto j:vactoriceanu[i]) { val=(val*23+j+13)%mod; } if(val!=0) { if(mp2[val]==0) { return 0; } else { mp2[val]--; } } vactoriceanu[i].clear(); } if(posible==1) { return 0; } return 1; } map<pair<int,int> ,int >frevals; std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C) { int n=N,culs=M,i; vector<int>ans; for(i=1;i<n;i++) { par[i]=P[i]; cop[P[i]].push_back(i); cul[i]=C[i]; } for(i=0;i<n;i++) { for(auto k:cop[i]) { has[i]=(has[i]*23+cul[k]+13)%mod; frevals[{i,cul[k]}]++; } for(auto k:cop[i]) { for(auto j:cop[k]) { if(frevals[{k,cul[j]}]>frevals[{i,cul[j]}]) { imp[i]=1; } } } } for(i=0;i<n ;i++) { ans.push_back(calc(i)); } return ans; }

Compilation message (stderr)

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:87:13: warning: unused variable 'culs' [-Wunused-variable]
   87 |     int n=N,culs=M,i;
      |             ^~~~
#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...