Submission #422704

#TimeUsernameProblemLanguageResultExecution timeMemory
422704oleh1421Split the Attractions (IOI19_split)C++17
40 / 100
138 ms27240 KiB
//#include "grader.cpp" #include "split.h" #include <bits/stdc++.h> typedef long long ll; using namespace std; const int N=200010; vector<int>g[N],t[N]; pair<int,int>gr[3]; int sz[N]; int P[N]; bool used[N]; void dfs(int v,int pr){ sz[v]=1; P[v]=pr; used[v]=true; for (int to:g[v]){ if (!used[to]){ t[v].push_back(to); t[to].push_back(v); dfs(to,v); sz[v]+=sz[to]; } } } int ans[N]; void Mark(int v,int ind){ if (!gr[ind].first) return; gr[ind].first--; ans[v]=gr[ind].second; // if (!ind) cout<<"OK "<<v<<" "<<gr[ind].first<<" "<<gr[ind].second<<endl; for (int to:t[v]){ if (ans[to]) continue; Mark(to,ind); } } bool DONE=false; void dfs1(int v,int pr){ if (DONE) return; vector<pair<int,int> >go; for (int to:g[v]){ if (to!=pr){ go.push_back({sz[to],to}); } } sort(go.begin(),go.end()); reverse(go.begin(),go.end()); if (go[0].first>=gr[0].first && go[0].first<=gr[1].first+gr[2].first){ if (go[0].first<=gr[0].first+gr[2].first){ ans[go[0].second]=gr[0].second; ans[v]=gr[1].second; Mark(go[0].second,0); Mark(v,1); // for (int i=0;i<7;i++) cout<<ans[i]<<" "; // cout<<endl; // cout<<"OK "<<v<<" "<<go[0].second<<endl; } else { ans[go[0].second]=gr[1].second; ans[v]=gr[0].second; Mark(go[0].second,1); Mark(v,0); } DONE=true; return; } if (go[0].first<gr[0].first) return; dfs1(go[0].first,v); } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { gr[0]={a,1}; gr[1]={b,2}; gr[2]={c,3}; sort(gr,gr+3); for (int i=0;i<p.size();i++){ g[p[i]].push_back(q[i]); g[q[i]].push_back(p[i]); } dfs(0,-1); for (int i=0;i<n;i++){ if (sz[i]>=gr[0].first && sz[i]<=n-gr[0].first){ if (sz[i]<=n-gr[1].first){ ans[P[i]]=gr[1].second; ans[i]=gr[0].second; Mark(P[i],1); Mark(i,0); } else { ans[P[i]]=gr[0].first; ans[i]=gr[1].first; Mark(P[i],0); Mark(i,1); } DONE=true; break; } } // dfs1(0,-1); if (DONE){ for (int i=0;i<n;i++){ if (!ans[i]) ans[i]=gr[2].second; } } vector<int>res; for (int i=0;i<n;i++) res.push_back(ans[i]); return res; } /** 9 10 4 2 3 0 1 0 2 0 3 0 4 0 6 0 8 1 7 3 7 4 5 5 6 */

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:73:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for (int i=0;i<p.size();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...