(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #534024

#TimeUsernameProblemLanguageResultExecution timeMemory
534024ivan_tudorPaprike (COI18_paprike)C++14
100 / 100
76 ms21076 KiB
#include<bits/stdc++.h> using namespace std; struct dphelp{ int nrc; long long csum; bool operator <(dphelp oth) const{ return csum < oth.csum; } }; long long k; const int N = 100005; dphelp dp[N]; long long val[N]; vector<int> gr[N]; void dfs(int nod, int dad){ dp[nod].csum = val[nod]; dp[nod].nrc = 0; vector<dphelp> smal; for(auto x:gr[nod]){ if(x == dad) continue; dfs(x, nod); dp[nod].nrc += dp[x].nrc; smal.push_back(dp[x]); } sort(smal.begin(), smal.end()); for(int i = 0; i < smal.size(); i++){ if(dp[nod].csum + smal[i].csum <= k){ dp[nod].csum += smal[i].csum; } else dp[nod].nrc++; } } int main() { //freopen(".in","r",stdin); ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int n; cin>>n>>k; for(int i = 1; i<=n; i++) cin>>val[i]; for(int i = 1; i<n; i++){ int x, y; cin>>x>>y; gr[x].push_back(y); gr[y].push_back(x); } dfs(1, 0); cout<<dp[1].nrc<<"\n"; return 0; }

Compilation message (stderr)

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