Submission #1026207

#TimeUsernameProblemLanguageResultExecution timeMemory
1026207vjudge1Paprike (COI18_paprike)C++17
100 / 100
74 ms24972 KiB
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; const int MAX_N=100000; long long int a[MAX_N]; vector<int>tree[MAX_N]; long long sub_tree_sum[MAX_N]; long long int k, rez=0; long long dfs1(int node, int p) { sub_tree_sum[node]=a[node]; multiset<int>s; for(int i=0; i<tree[node].size(); i++) { if(tree[node][i]!=p) { sub_tree_sum[node]+=dfs1(tree[node][i], node); s.insert(sub_tree_sum[tree[node][i]]); } } if(sub_tree_sum[node]>k) { long long sum=a[node]; for(auto it=s.begin(); it!=s.end(); it++) { if(sum+*it<=k) { sum+=*it; } else { rez++; sub_tree_sum[node]-=*it; } } } return sub_tree_sum[node]; } int main() { int n; cin>>n>>k; for(int i=0; i<n; i++) { cin>>a[i]; } for(int i=0; i<n-1; i++) { int aa, bb; cin>>aa>>bb; aa--; bb--; tree[aa].push_back(bb); tree[bb].push_back(aa); } dfs1(0, 0); cout<<rez; return 0; }

Compilation message (stderr)

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