제출 #71601

#제출 시각아이디문제언어결과실행 시간메모리
71601algorithm16Paprike (COI18_paprike)C++14
100 / 100
319 ms100676 KiB
#include<iostream> #include<vector> #include<algorithm> using namespace std; typedef long long int llint; llint parent[3000000],brojac=0,b1=0; vector <llint> c[3000000]; llint sum[3000000]; vector <llint> v; llint n,k; llint dfs(llint x) { vector <llint> v2; llint mini=10000000,b2=0,b3=0,b4=0,b5=0,sum3=0; for(llint i=0;i<c[x].size();i++) { if(parent[x]==c[x][i]) continue; //cout <<x<<" "<<c[x][i]<<endl; //sum2+=sum[c[x][i]]; /*if(mini==-1) mini=dfs(c[x][i],brojac2,x); else if(dfs(c[x][i],brojac2,x)<mini) mini=dfs(c[x][i],brojac2,x);*/ //cout <<x<<" "<<dfs(c[x][i],0)<<endl; int sum2=dfs(c[x][i]); sum3+=sum2; /*if(sum2+v[x]>k) { b2+=1; //b1+=sum2; //sum[x]-=b1; //cout <<v[x]<<" "<<sum2<<" "<<"uvjet1"<<endl; brojac+=1; sum[x]-=sum2; } else { v.push_back() b4+=sum2; b3+=sum2; b5+=1; if(sum2<mini) mini=sum2; }*/ v2.push_back(sum2); } /*b4-=mini; llint s=c[x].size(); if(s-b2-1>1) { //cout <<v[x]<<" "<<s-b2-1<<" "<<"uvjet2"<<endl; b3-=b4; //b1+=maxi; brojac+=b5-1; } else if(x==0 && s-b2>1) { //cout <<v[x]<<" "<<s-b2-1<<" "<<"uvjet2"<<endl; b3-=b4; //b1+=maxi; brojac+=1; } //if(x==0) cout <<b3<<" "<<maxi<<endl; sum[x]=v[x]+b3; //sum[x]-=b1;*/ sum3+=v[x]; int index=v2.size()-1; sort(v2.begin(),v2.end()); while(sum3>k) { sum3-=v2[index]; index-=1; brojac+=1; } return sum3; } void dfs2(llint x,llint par) { parent[x]=par; for(llint i=0;i<c[x].size();i++) { if(c[x][i]==par) continue; dfs2(c[x][i],x); //sum[x]+=sum[c[x][i]]; } //sum[x]+=v[x]; } int main() { cin >> n >> k; vector <pair<llint,llint> > y; for(int i=0;i<n;i++) { llint x; cin >> x; v.push_back(x); } for(llint i=0;i<n-1;i++) { llint a,b; cin >> a >> b; y.push_back(make_pair(a-1,b-1)); c[a-1].push_back(b-1); c[b-1].push_back(a-1); } dfs2(0,-1); dfs(0); /*for(int i=0;i<n;i++) { cout <<sum[i]<<" "; } cout <<endl;*/ cout <<brojac; return 0; }

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

paprike.cpp: In function 'llint dfs(llint)':
paprike.cpp:14:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(llint i=0;i<c[x].size();i++) {
                ~^~~~~~~~~~~~
paprike.cpp:13:8: warning: unused variable 'mini' [-Wunused-variable]
  llint mini=10000000,b2=0,b3=0,b4=0,b5=0,sum3=0;
        ^~~~
paprike.cpp:13:22: warning: unused variable 'b2' [-Wunused-variable]
  llint mini=10000000,b2=0,b3=0,b4=0,b5=0,sum3=0;
                      ^~
paprike.cpp:13:27: warning: unused variable 'b3' [-Wunused-variable]
  llint mini=10000000,b2=0,b3=0,b4=0,b5=0,sum3=0;
                           ^~
paprike.cpp:13:32: warning: unused variable 'b4' [-Wunused-variable]
  llint mini=10000000,b2=0,b3=0,b4=0,b5=0,sum3=0;
                                ^~
paprike.cpp:13:37: warning: unused variable 'b5' [-Wunused-variable]
  llint mini=10000000,b2=0,b3=0,b4=0,b5=0,sum3=0;
                                     ^~
paprike.cpp: In function 'void dfs2(llint, llint)':
paprike.cpp:69:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(llint i=0;i<c[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...