Submission #105574

#TimeUsernameProblemLanguageResultExecution timeMemory
105574keko37Paprike (COI18_paprike)C++14
100 / 100
129 ms21980 KiB
#include<bits/stdc++.h> using namespace std; typedef long long llint; const int MAXN = 100005; llint n, k; llint val[MAXN], dp[MAXN]; vector <int> v[MAXN]; llint dfs (int x, int rod) { llint res = val[x]; vector <llint> r; for (int i=0; i<v[x].size(); i++) { int sus = v[x][i]; if (sus == rod) continue; r.push_back(dfs(sus, x)); res += r.back(); dp[x] += dp[sus]; } sort(r.begin(), r.end()); while (res > k) { res -= r.back(); dp[x]++; r.pop_back(); } return res; } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i=1; i<=n; i++) { cin >> val[i]; } for (int i=0; i<n-1; i++) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } dfs(1, 0); cout << dp[1]; return 0; }

Compilation message (stderr)

paprike.cpp: In function 'llint dfs(int, int)':
paprike.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<v[x].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...