Submission #146827

#TimeUsernameProblemLanguageResultExecution timeMemory
146827Bodo171Split the Attractions (IOI19_split)C++14
0 / 100
235 ms25264 KiB
#include "split.h" #include <vector> #include <iostream> #include <algorithm> using namespace std; const int nmax=100005; pair<int,int> col[5]; vector<int> res; vector<int> v[nmax],ad[nmax],arb[nmax]; int l[nmax],r[nmax],rep[nmax],w[nmax],pond[nmax],big[nmax],q[nmax],viz[nmax],valid[nmax],tt[nmax]; int nr,x,sum,p,u,i,j,k,nod,A,act,gasit,n,cen; void dfs(int x) { rep[++nr]=x;l[x]=nr; w[x]=1; for(int i=0;i<arb[x].size();i++) if(!w[arb[x][i]]) { tt[arb[x][i]]=x; dfs(arb[x][i]); w[x]+=w[arb[x][i]]; big[x]=max(big[x],w[arb[x][i]]); } r[x]=nr; } void bfs(int x) { q[u=1]=x;sum=pond[x];viz[x]=1; for(p=1;p<=u;p++) { x=q[p]; for(i=0;i<ad[x].size();i++) { nod=ad[x][i]; if(!viz[nod]) { viz[nod]=1; sum+=pond[nod]; q[++u]=nod; if(sum>=A) { for(j=1;j<=u;j++) { act=q[j]; for(k=l[act];k<=r[act];k++) valid[rep[k]]=1; gasit=1; return; } } } } } } void coloreaza(int cate,int C) { int start=0; for(i=0;i<n;i++) { if(valid[i]) start=i; viz[i]=0; } q[u=1]=start; for(p=1;p<=u;p++) { x=q[p]; res[x]=C; if(p==cate) return; for(i=0;i<v[x].size();i++) if(valid[v[x][i]]&&(!viz[v[x][i]])) { q[++u]=v[x][i]; viz[v[x][i]]=1; } } } vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) { n=N; res.resize(n); col[0]={a,1}; col[1]={b,2}; col[2]={c,3}; sort(col,col+3); A=col[0].first; int m=p.size(); for(i=0;i<m;i++) { v[p[i]].push_back(q[i]); v[q[i]].push_back(p[i]); } for(i=0;i<n;i++) arb[i]=v[i]; dfs(0); for(i=0;i<n;i++) arb[i].clear(); for(i=1;i<n;i++) { arb[tt[i]].push_back(i); arb[i].push_back(tt[i]); } for(i=0;i<n;i++) if(n-w[i]<=n/2&&big[i]<=n/2) cen=i; for(i=0;i<n;i++) w[i]=0; nr=0; dfs(cen); for(i=0;i<arb[cen].size();i++) { x=arb[cen][i]; for(j=l[x];j<=r[x];j++) { nod=rep[j]; tt[nod]=x; } pond[x]=w[x]; if(pond[x]>=A&&(!gasit)) { gasit=1; for(j=l[x];j<=r[x];j++) { valid[rep[j]]=1; } } } for(i=0;i<m;i++) if(p[i]!=cen&&q[i]!=cen) { ad[tt[p[i]]].push_back(tt[q[i]]); ad[tt[q[i]]].push_back(tt[p[i]]); } /*if(!gasit) for(int it=0;it<v[cen].size();it++) { if(!viz[v[cen][it]]) bfs(v[cen][it]); }*/ if(!gasit) return res; coloreaza(col[0].first,col[0].second); for(i=0;i<n;i++) valid[i]^=1; coloreaza(col[1].first,col[1].second); for(i=0;i<n;i++) if(!res[i]) res[i]=col[2].second; return res; }

Compilation message (stderr)

split.cpp: In function 'void dfs(int)':
split.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<arb[x].size();i++)
                 ~^~~~~~~~~~~~~~
split.cpp: In function 'void bfs(int)':
split.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<ad[x].size();i++)
                 ~^~~~~~~~~~~~~
split.cpp: In function 'void coloreaza(int, int)':
split.cpp:70:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:109:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<arb[cen].size();i++)
             ~^~~~~~~~~~~~~~~~
split.cpp:144:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(i=0;i<n;i++)
     ^~~
split.cpp:147:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  return res;
  ^~~~~~
#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...