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

#TimeUsernameProblemLanguageResultExecution timeMemory
241013topovikPaprike (COI18_paprike)C++14
100 / 100
182 ms16132 KiB
#include <bits/stdc++.h> #define f first #define s second #define pb push_back #define INF 1000000000 #define N (long)1e6 using namespace std; typedef long long ll; typedef long double ld; vector <vector <ll> > a; ll n,k; ll b[N]; ll ans; ll Rec(ll x, ll y) { vector <ll> c; ll sum=b[x]; for (ll i=0; i<a[x].size(); i++) if (a[x][i]!=y) c.pb(Rec(a[x][i],x)),sum+=c.back(); sort(c.begin(),c.end()); reverse(c.begin(),c.end()); for (ll i=0; sum>k; i++) sum-=c[i],ans++; return sum; } int main() { cin>>n>>k; for (ll i=0; i<n; i++) cin>>b[i]; a.resize(n); for (ll i=0; i<n-1; i++) { ll x,y; cin>>x>>y; a[--x].pb(--y); a[y].pb(x); } Rec(0,0); cout<<ans; }

Compilation message (stderr)

paprike.cpp: In function 'll Rec(ll, ll)':
paprike.cpp:24:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (ll i=0; i<a[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...