제출 #928933

#제출 시각아이디문제언어결과실행 시간메모리
92893312345678Paprike (COI18_paprike)C++17
100 / 100
36 ms19616 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=1e5+5; ll n, k, dp[nx], u, v, res; vector<int> d[nx]; void dfs(int u, int p) { vector<int> tmp; for (auto v:d[u]) if (v!=p) dfs(v, u), tmp.push_back(dp[v]); sort(tmp.begin(), tmp.end()); for (auto x:tmp) { if (dp[u]+x>k) res++; else dp[u]+=x; } } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>k; for (int i=1; i<=n; i++) cin>>dp[i]; for (int i=0; i<n-1; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u); dfs(1, 1); cout<<res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...