Submission #429772

#TimeUsernameProblemLanguageResultExecution timeMemory
429772rumen_mSplit the Attractions (IOI19_split)C++17
33 / 100
885 ms1048580 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1e5+5; vector<int> res; vector <int> g[maxn]; int leftt; int a,b,c,n; int ans[4]; void dfs(int v, int par) { if(leftt==0)return ; leftt--; res[v] = 2; int i; for(auto u:g[v]) { if(res[u]!=0)continue; dfs(u,v); } } int subsize[maxn]; bool FL = false; void dfs3(int v, int par, int id) { if(leftt==0)return ; leftt--; res[v] = id; for(auto u:g[v]) { if(u==par||res[u]!=0)continue; dfs3(u,v,id); } } void dfs2(int v, int par) { //cout<<v<<" "<<par<<endl; int i; subsize[v] = 1; for(auto u:g[v]) { if(u==par)continue; dfs2(u,v); subsize[v]+=subsize[u]; if(!FL&&subsize[u]>=a&&n-subsize[u]>=b){leftt = a;dfs3(u,v,ans[1]);leftt = b;dfs3(v,-1,ans[2]);FL=true;return;} if(!FL&&subsize[u]>=b&&n-subsize[u]>=a){leftt = b;dfs3(u,v,ans[2]);leftt = a;dfs3(v,-1,ans[1]);FL=true;return;} } // cout<<v<<" & "<<subsize[v]<<endl; } vector<int> find_split(int _n, int _a, int _b, int _c, vector<int> p, vector<int> q) { n = _n; a = _a; b = _b; c = _c; res.resize(n); int i; for(i=0;i<p.size();i++) { g[p[i]].push_back(q[i]); g[q[i]].push_back(p[i]); } if(a==1) { leftt = b; dfs(0,-1); bool fl = false; for(i=0;i<n;i++) { if(res[i])continue; if(!fl){res[i] = 1; fl=true;} else res[i] = 3; } } else { // cout<<"OK"<<endl; ans[1] = 1; ans[2] = 2; ans[3] = 3; if(a>b){swap(a,b);swap(ans[1],ans[2]);} if(a>c){swap(a,c);swap(ans[1],ans[3]);} if(b>c){swap(b,c);swap(ans[2],ans[3]);} dfs2(1,-1); if(!FL)return res; for(i=0;i<n;i++) { if(res[i]==0)res[i] = ans[3]; } } return res; }

Compilation message (stderr)

split.cpp: In function 'void dfs(int, int)':
split.cpp:15:9: warning: unused variable 'i' [-Wunused-variable]
   15 |     int i;
      |         ^
split.cpp: In function 'void dfs2(int, int)':
split.cpp:40:9: warning: unused variable 'i' [-Wunused-variable]
   40 |     int i;
      |         ^
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:62:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for(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...