제출 #71589

#제출 시각아이디문제언어결과실행 시간메모리
71589algorithm16Paprike (COI18_paprike)C++14
13 / 100
260 ms99564 KiB
#include<iostream> #include<vector> 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; int dfs(int x) { llint mini=10000000,b2=0,b3=0,b4=0,b5=0; for(int 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]); if(sum2+v[x]>k) { b2+=1; //b1+=sum2; //sum[x]-=b1; //cout <<v[x]<<" "<<sum2<<" "<<"uvjet1"<<endl; brojac+=1; sum[x]-=sum2; } else { b4+=sum2; b3+=sum2; b5+=1; if(sum2<mini) mini=sum2; } } b4-=mini; int 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; return sum[x]; } void dfs2(int x,int par) { parent[x]=par; for(int 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++) { int x; cin >> x; v.push_back(x); } for(int i=0;i<n-1;i++) { int 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 'int dfs(int)':
paprike.cpp:12:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<c[x].size();i++) {
              ~^~~~~~~~~~~~
paprike.cpp: In function 'void dfs2(int, int)':
paprike.cpp:56:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int 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...