Submission #967507

#TimeUsernameProblemLanguageResultExecution timeMemory
967507lanaskaricaPaprike (COI18_paprike)C++14
100 / 100
45 ms19284 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair <int, int> #define fi first #define se second const int MAXN = 1e5 + 5; int n, k, rj, arr[MAXN]; vector <int> v[MAXN]; int rek(int x, int p) { vector <int> r; for (auto e : v[x]) { if (e == p) continue; r.push_back(rek(e, x)); } // cout << "ispis: " << x << endl; sort(r.begin(), r.end()); int zb = arr[x], y = 0; for (int i = 0; i < r.size(); i++) { // cout << r[i] << " "; if (zb + r[i] > k) break; zb += r[i]; y = i + 1; // cout << "."; } // cout << endl; // cout << zb << " " << r.size() << " " << y << endl; rj += (r.size() - y); return zb; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int a, b; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 0; i < n - 1; i++) { cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } rj = 0; rek(1, 1); cout << rj << "\n"; return 0; }

Compilation message (stderr)

paprike.cpp: In function 'int rek(int, int)':
paprike.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < r.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...