이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |