Submission #724946

#TimeUsernameProblemLanguageResultExecution timeMemory
724946lukadupliPaprike (COI18_paprike)C++14
100 / 100
160 ms26100 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 3e5 + 5; int n, k, arr[MAXN]; vector<int> adj[MAXN]; ll sum[MAXN]; int solve(int node, int par){ int ret = 0; sum[node] = arr[node]; vector<int> v; for(int nxt : adj[node]){ if(nxt != par){ ret += solve(nxt, node); sum[node] += sum[nxt]; v.push_back(sum[nxt]); } } sort(v.begin(), v.end(), greater<int>()); for(int i = 0; i < v.size() && sum[node] > k; i++){ sum[node] -= v[i]; ret++; } return ret; } int main() { cin >> n >> k; for(int i = 1; i <= n; i++) cin >> arr[i]; for(int i = 0; i < n - 1; i++){ int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } cout << solve(1, -1); return 0; }

Compilation message (stderr)

paprike.cpp: In function 'int solve(int, int)':
paprike.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < v.size() && sum[node] > 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...