(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 #1117955

#TimeUsernameProblemLanguageResultExecution timeMemory
1117955vjudge1Paprike (COI18_paprike)C++17
100 / 100
46 ms19960 KiB
#pragma GCC optimize("O3") #include<bits/stdc++.h> #define ll long long #define endl "\n" #define AI ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; vector<ll>val; vector<vector<ll>>edge; vector<ll>check; ll k,c=0; ll dfs(ll i) { check[i]=1; priority_queue<ll>pq; ll res=val[i],x; for(ll j:edge[i]) { if(!check[j]) { x=dfs(j); pq.push(x); res+=x; } } // cout<<res<<' '; while(res>k and pq.size()) { res-=pq.top(); c++; pq.pop(); } return res; } int main() { AI //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ll n,a,b,i; cin>>n>>k; val.resize(n+1); for(i=1;i<=n;i++) cin>>val[i]; edge.resize(n+1); check.resize(n+1,0); for(i=1;i<n;i++) { cin>>a>>b; edge[a].push_back(b); edge[b].push_back(a); } dfs(1); cout<<c<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...