Submission #987407

#TimeUsernameProblemLanguageResultExecution timeMemory
987407activedeltorreBeech Tree (IOI23_beechtree)C++17
0 / 100
2045 ms20180 KiB
#include "beechtree.h" #include <vector> #include <queue> #include <iostream> #include <map> using namespace std; vector<int>cop[200005]; int cul[200005]; int imp[200005]; int dist[200005]; int par[200005]; vector<int>vecus; bool cmp(int a,int b) { //if(dist[a]==dist[b]) // { return cop[a].size()>cop[b].size(); // } // return dist[a]<dist[b]; } map<int,int>mp; map<int,int>mp2; int calc(int curr) { mp2.clear(); int cur; queue<int>qu; dist[curr]=0; qu.push(curr); vecus.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); } } //cout<<curr<<" "<<imp[curr]<<" :"; for(auto i:vecus) { if(i!=curr) { if(par[i]!=vecus[mp2[cul[i]]]) { return 0; } mp2[cul[i]]++; } } // cout<<'\n'; return 1; } 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++) { mp.clear(); for(auto k:cop[i]) { mp[cul[k]]++; if(mp[cul[k]]==2) { 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:59:13: warning: unused variable 'culs' [-Wunused-variable]
   59 |     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...