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

#TimeUsernameProblemLanguageResultExecution timeMemory
96726losmi247Paprike (COI18_paprike)C++14
100 / 100
113 ms19064 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 1e5+43; ll h[N],sz[N],n,k; vector <ll> graf[N]; bool visited[N]; ll resi(ll a){ visited[a] = 1; ll sol = 0; vector <ll> ch; for(auto f : graf[a]){ if(visited[f]){ continue; } sol += resi(f); sz[a] += sz[f]; ch.push_back(sz[f]); } sz[a] += h[a]; if(sz[a] <= k){ return sol; } sort(ch.rbegin(),ch.rend()); for(long i = 0; i < ch.size() && sz[a] > k; i++){ sz[a] -= ch[i]; sol++; } return sol; } int main(){ ios_base::sync_with_stdio(false); cin >> n >> k; for(long i = 1; i <= n; i++){ cin >> h[i]; } for(long i = 1; i < n; i++){ ll u,v; cin >> u >> v; graf[u].push_back(v); graf[v].push_back(u); } cout << resi(1) << endl; }

Compilation message (stderr)

paprike.cpp: In function 'll resi(ll)':
paprike.cpp:25:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long i = 0; i < ch.size() && sz[a] > k; i++){
                     ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...