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

#TimeUsernameProblemLanguageResultExecution timeMemory
72969badrovinhoPaprike (COI18_paprike)C++14
100 / 100
235 ms46360 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <cstdio> #include <cstdlib> using namespace std; long long n,k; long long rez=0; long long hljut[100005]; long long a[100005]; long long b[100005]; vector <long long> graf[100005]; int dfs(long long x, long long par){ vector <long long> v; for (int i = 0; i < (long long)(graf[x]).size(); i++){ long long child = graf[x][i]; if (child == par)continue; v.push_back(dfs(child, x)); } sort(v.begin(), v.end()); long long sum = 0; sum += hljut[x-1]; for (long long j = 0; j < v.size(); j++) sum += v[j]; for (long long i = v.size()-1; i >= 0; i--){ if (sum>k){ sum -= v[i]; rez++; } else break; } return sum; } int main (){ cin >> n >> k; for (long long i=0; i<n; i++){ cin >> hljut[i]; } for (long long i=0; i<n-1; i++){ cin >> a[i] >> b[i]; graf[a[i]].push_back(b[i]); graf[b[i]].push_back(a[i]); } dfs(1,0); cout << rez; return 0; }

Compilation message (stderr)

paprike.cpp: In function 'int dfs(long long int, long long int)':
paprike.cpp:29:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (long long j = 0; j < v.size(); j++) sum += v[j];
                           ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...