제출 #146814

#제출 시각아이디문제언어결과실행 시간메모리
146814Bodo171Split the Attractions (IOI19_split)C++14
0 / 100
110 ms15840 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]; 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<v[x].size();i++) if(!w[v[x][i]]) { dfs(v[x][i]); w[x]+=w[v[x][i]]; big[x]=max(big[x],w[v[x][i]]); } r[x]=nr; } void bfs(int x) { q[u=1]=x;sum=pond[x]; 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]; if(sum>=A) { for(j=1;j<=u;j++) { act=rep[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]); } dfs(0); for(i=0;i<n;i++) if(n-w[x]<=n/2&&big[x]<=n/2) cen=x; for(i=1;i<=n;i++) w[i]=0; nr=0; dfs(cen); for(i=0;i<v[cen].size();i++) { x=v[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++) { 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; }

컴파일 시 표준 에러 (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<v[x].size();i++)
                 ~^~~~~~~~~~~~
split.cpp: In function 'void bfs(int)':
split.cpp:31: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:68: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:99:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<v[cen].size();i++)
             ~^~~~~~~~~~~~~~
split.cpp:123:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int it=0;it<v[cen].size();it++)
                  ~~^~~~~~~~~~~~~~
split.cpp:133:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(i=0;i<n;i++)
     ^~~
split.cpp:136: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...