(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #386659

#TimeUsernameProblemLanguageResultExecution timeMemory
386659loctildorePaprike (COI18_paprike)C++14
100 / 100
70 ms17900 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second #define x first #define y second #define elif else if #define endl '\n' #define all(x) begin(x), end(x) int n,k,x,y,total; int spice[100069]; vector<int> gph[100069]; bool done[100069]; int dfs(int node){ done[node]=true; vector<int> vct; for (int i:gph[node]) { if (!done[i]) { vct.push_back(dfs(i)); } } int cur=spice[node]; sort(all(vct)); for (int i : vct) { if (cur+i<=k) { cur+=i; } else{ total++; } } return cur; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>k; for (int i = 0; i < n; i++) { cin>>spice[i]; } for (int i = 0; i < n-1; i++) { cin>>x>>y; x--;y--; gph[x].push_back(y); gph[y].push_back(x); } dfs(0); cout<<total<<endl; 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...