제출 #760566

#제출 시각아이디문제언어결과실행 시간메모리
760566alexander707070Split the Attractions (IOI19_split)C++14
0 / 100
408 ms1048576 KiB
#include<bits/stdc++.h> #define MAXN 200007 using namespace std; int n,sz[MAXN],br,a,b,c; vector<int> v[MAXN],ans; bool ok; char comp[MAXN],s; void mark(int x,int p, char d){ if(br==0)return; comp[x]=d; br--; for(int i=0;i<v[x].size();i++){ if(v[x][i]==p)continue; mark(v[x][i],x,d); } } void dfs(int x,int p){ sz[x]=1; for(int i=0;i<v[x].size();i++){ if(v[x][i]==p)continue; dfs(v[x][i],x); sz[x]+=sz[v[x][i]]; } if(sz[x]>=a and n-sz[x]<=max(b,c) and ok){ br=a; mark(x,p,'a'); ok=false; if(n-sz[x]<=b){br=b; mark(p,x,'b'); s='c';} else {br=c; mark(p,x,'c'); s='b';} }else if(sz[x]>=b and n-sz[x]<=max(a,c) and ok){ br=b; mark(x,p,'b'); ok=false; if(n-sz[x]<=a){br=a; mark(p,x,'a'); s='c';} else {br=c; mark(p,x,'c'); s='a';} }else if(sz[x]>=c and n-sz[x]<=max(a,b) and ok){ br=c; mark(x,p,'c'); ok=false; if(n-sz[x]<=b){br=b; mark(p,x,'b'); s='a';} else {br=a; mark(p,x,'a'); s='b';} } } 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; for(int i=0;i<n-1;i++){ p[i]++; q[i]++; v[p[i]].push_back(q[i]); v[q[i]].push_back(p[i]); } ok=true; dfs(1,0); ans.resize(n); if(ok)return ans; for(int i=1;i<=n;i++){ if(comp[i]<'a' or comp[i]>'c')comp[i]=s; ans[i-1]=comp[i]-'a'+1; } return ans; } /* int main(){ find_split(9, 4, 2, 3, {0, 0, 0, 0, 0, 0, 1, 3, 4, 5}, {1, 2, 3, 4, 6, 8, 7, 7, 5, 6}); for(int i=0;i<ans.size();i++){ cout<<ans[i]<<" "; } } */

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

split.cpp: In function 'void mark(int, int, char)':
split.cpp:14:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
split.cpp: In function 'void dfs(int, int)':
split.cpp:22:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i=0;i<v[x].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...