(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 #465438

#TimeUsernameProblemLanguageResultExecution timeMemory
465438osmanallazovPaprike (COI18_paprike)C++14
100 / 100
175 ms17492 KiB
#include <bits/stdc++.h> using namespace std; long long n,k; long long ans=0; long long val[100005]; long long a[100005]; long long b[100005]; vector<long long>qraf[100005]; int dfs(long long x, long long par){ vector<long long>v; for(long long i=0;i<(long long)(qraf[x]).size();i++){ long long child=qraf[x][i]; if(child==par) continue; v.push_back(dfs(child,x)); } sort(v.begin(),v.end()); long long sum=0; sum=sum+val[x-1]; for(long long i=0;i<v.size();i++) sum+=v[i]; for(long long i=v.size()-1;i>=0;i--){ if(sum>k){ sum-=v[i]; ans++; } else{break;} } return sum; } int main(){ cin>>n>>k; for(int i=0; i<n; i++){ cin>>val[i]; } for(int i=0; i<n-1; i++){ cin>>a[i]>>b[i]; qraf[a[i]].push_back(b[i]); qraf[b[i]].push_back(a[i]); } dfs(1,0); cout<<ans; }

Compilation message (stderr)

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