Submission #963709

#TimeUsernameProblemLanguageResultExecution timeMemory
963709Ivo_12Paprike (COI18_paprike)C++98
100 / 100
57 ms23632 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back using namespace std; struct node { vector < int > chi; int par = -1; ll val = 0; }; const int N = 100010; node tree[N]; int n; int k; vector < int > edges[N]; int sol; void dfs( int pos ) { for(int i = 0; i < edges[pos].size(); i++) { if(edges[pos][i]!=tree[pos].par) { tree[edges[pos][i]].par=pos; tree[pos].chi.pb(edges[pos][i]); dfs(edges[pos][i]); } } } ll sumover( int pos ) { vector < ll > chivals; ll total = tree[pos].val; for(int i = 0; i < tree[pos].chi.size(); i++) { chivals.pb(sumover(tree[pos].chi[i])); total+=chivals[i]; } sort(chivals.begin(), chivals.end()); while(total>k) { total-=(*--chivals.end()); chivals.pop_back(); sol++; } return total; } int main ( void ) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 0; i < n; i++) { cin >> tree[i].val; } int a, b; for(int i = 0; i < n-1; i++) { cin >> a >> b; edges[--a].pb(--b); edges[b].pb(a); } dfs(0); sumover(0); cout << sol; return 0; }

Compilation message (stderr)

paprike.cpp: In function 'void dfs(int)':
paprike.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(int i = 0; i < edges[pos].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~
paprike.cpp: In function 'long long int sumover(int)':
paprike.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for(int i = 0; i < tree[pos].chi.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...