# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71573 | aklo | Paprike (COI18_paprike) | C++14 | 177 ms | 14116 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,r=0,b,br=0;
int niz[100005],zbr[100005],bio[100005];
pair <int, int> a[100005];
vector <int> v[100005];
vector <int> ve;
void dfs(int x){
bio[x]=1;
if(zbr[x]+niz[x]<=k){
for(int i=0; i<ve.size(); i++){
zbr[ve[i]]+=niz[x];
}
zbr[x]+=niz[x];
if(r<ve.size()){
ve[r]=x;
}
else{
ve.push_back(x);
}
r++;
for(int i=0; i<v[x].size(); i++){
if(bio[v[x][i]]==0){
zbr[v[x][i]]=zbr[x];
dfs(v[x][i]);
}
}
}
else{
br++;
//cout<<x<<endl<<endl;
b=ve.size();
for(int i=0; i<b; i++){
ve.pop_back();
}
r=0;
zbr[x]=niz[x];
ve.push_back(x);
r++;
for(int i=0; i<v[x].size(); i++){
if(bio[v[x][i]]==0){
zbr[v[x][i]]=zbr[x];
dfs(v[x][i]);
}
}
}
}
int main () {
cin>>n>>k;
for(int i=1; i<=n; i++){
cin>>niz[i];
}
for(int i=1; i<n; i++){
cin>>a[i].first;
cin>>a[i].second;
v[a[i].first].push_back(a[i].second);
v[a[i].second].push_back(a[i].first);
}
dfs(1);
cout<<br<<endl;
//for(int i=1; i<=n; i++){
// cout<<zbr[i]<<endl;
//}
return 0;
}
Compilation message (stderr)
# | 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... |