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

#TimeUsernameProblemLanguageResultExecution timeMemory
208347MatesV13Paprike (COI18_paprike)C++11
100 / 100
93 ms22648 KiB
#include <bits/stdc++.h> using namespace std; long long n, k, h[100005], a, b, rez, ans; vector<long long> c[100005]; vector<long long> l[100005]; long long lj[100005]; void dfs(int idx, int prev){ if (lj[idx]) return; lj[idx]=h[idx]; for (int i=0; i<c[idx].size(); i++){ if (c[idx][i]==prev) continue; dfs(c[idx][i], idx); l[idx].push_back(lj[c[idx][i]]); } sort(l[idx].begin(), l[idx].end()); reverse(l[idx].begin(), l[idx].end()); for (int i=0; i<l[idx].size(); i++) lj[idx]+=l[idx][i]; for (int i=0; lj[idx]>k; i++){ lj[idx]-=l[idx][i]; rez++; } return; } int main (){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i=1; i<=n; i++) cin >> h[i]; for (int i=1; i<n; i++){ cin >> a >> b; c[a].push_back(b); c[b].push_back(a); } dfs(1, -1); cout << rez; return 0; }

Compilation message (stderr)

paprike.cpp: In function 'void dfs(int, int)':
paprike.cpp:10:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<c[idx].size(); i++){
                ~^~~~~~~~~~~~~~
paprike.cpp:17:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<l[idx].size(); 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...