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

#TimeUsernameProblemLanguageResultExecution timeMemory
572117MODDIPaprike (COI18_paprike)C++14
100 / 100
134 ms21092 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define mp make_pair #define pb push_back using namespace std; int n, q; vi G[100010], sum, size; ll rez = 0; void dfs(int at, int parent){ vl deca; ll gol = G[at].size() - 1; if(at == 0) gol++; for(auto it : G[at]){ if(it == parent) continue; dfs(it, at); deca.pb(size[it]); } sort(deca.begin(), deca.end()); for(auto it : deca){ if(size[at] + it <= q){ size[at] += it; gol--; } else{ rez += gol; return; } } } int main(){ cin>>n>>q; sum.resize(n); size.resize(n); ll mby = 0; for(int i = 0; i < n; i++){ cin>>sum[i]; mby += sum[i]; size[i] = sum[i]; } for(int i = 0; i < n - 1; i++){ int a, b; cin>>a>>b; a--; b--; G[a].pb(b); G[b].pb(a); } if(mby <= q) { cout<<0<<endl; return 0; } dfs(0, -1); cout<<rez<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...