제출 #868565

#제출 시각아이디문제언어결과실행 시간메모리
868565amirhoseinfar1385Paprike (COI18_paprike)C++17
100 / 100
38 ms19568 KiB
#include<bits/stdc++.h> using namespace std; const int maxn=100000+10; vector<int>adj[maxn]; long long val[maxn]; int n,k; int res=0; long long solve(int u=1,int par=-1){ vector<int>v; for(auto x:adj[u]){ if(x!=par){ v.push_back(solve(x,u)); } } sort(v.begin(),v.end()); long long suma=val[u]; for(int i=0;i<(int)v.size();i++){ if(suma+v[i]<=k){ suma+=v[i]; continue; } else{ res++; } } return suma; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>k; for(int i=1;i<=n;i++){ cin>>val[i]; } for(int i=1;i<=n-1;i++){ int u,v; cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); } solve(); cout<<res<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...