제출 #422700

#제출 시각아이디문제언어결과실행 시간메모리
422700oleh1421Split the Attractions (IOI19_split)C++17
22 / 100
97 ms16072 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]; pair<int,int>gr[3]; int sz[N]; int P[N]; void dfs(int v,int pr){ sz[v]=1; P[v]=pr; for (int to:g[v]){ if (to!=pr){ 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:g[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]); } if (p.size()==n-1){ 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; } /** 6 5 2 2 2 0 1 0 2 0 3 0 4 0 5 */

컴파일 시 표준 에러 (stderr) 메시지

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