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

#TimeUsernameProblemLanguageResultExecution timeMemory
531626Vladth11Paprike (COI18_paprike)C++14
100 / 100
129 ms23812 KiB
#include <bits/stdc++.h> #define debug(x) cerr << #x << " " << x << "\n" #define debugs(x) cerr << #x << " " << x << " " using namespace std; typedef long long ll; typedef pair <ll, ll> pii; typedef pair <long double, pii> muchie; const ll NMAX = 100001; const ll VMAX = 1000001; const ll INF = (1LL << 60); const ll MOD = 1000000007; const ll BLOCK = 447; const ll nr_of_bits = 21; vector <int> v[NMAX]; pii scor[NMAX]; int h[NMAX], k; void DFS(int node, int p){ ll s = h[node]; priority_queue <ll> pq; int sum = 0, cati = 0; for(auto x : v[node]){ if(x == p) continue; DFS(x, node); s += scor[x].second; sum += scor[x].first; pq.push(scor[x].second); } ll cnt = 0; while(pq.size() && s > k){ s -= pq.top(); cnt++; pq.pop(); } scor[node].first = cnt + sum; scor[node].second = s; } int main() { //ifstream cin("niceset.in"); //ofstream cout("niceset.out"); int n, i; cin >> n >> k; for(i = 1; i <= n; i++) cin >> h[i]; for(i = 1; i < n; i++){ int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } DFS(1, 0); cout << scor[1].first << "\n"; return 0; }

Compilation message (stderr)

paprike.cpp: In function 'void DFS(int, int)':
paprike.cpp:24:18: warning: unused variable 'cati' [-Wunused-variable]
   24 |     int sum = 0, cati = 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...