Submission #861985

#TimeUsernameProblemLanguageResultExecution timeMemory
861985RifalPaprike (COI18_paprike)C++14
100 / 100
44 ms24404 KiB
#include <bits/stdc++.h> #include <fstream> #define endl '\n' #define mod 998244353 #define INF 900000000 //#define cin fin //#define cout fout //#define fi first //#define se second using namespace std; //ofstream fout("intel.out"); //ifstream fin("intel.in"); long long n, k, ans = 0; const int Max = 1e5 + 5; vector<int> v[Max]; long long sum[Max]; void dfs(int s, int p) { multiset<long long> st; for(auto i : v[s]) { if(i != p) { dfs(i,s); st.insert(sum[i]); } } int cnt = 0; // cout << s << 'k' << endl; for(auto i : st) { if(sum[s]+i <= k) { // cout << i << 'l' << endl; sum[s] += i; cnt++; } else { break; } } ans += st.size()-cnt; } int main() { ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); cin >> n >> k; for(int i = 1; i <= n; i++) cin >> sum[i]; for(int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } dfs(1,0); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...