Submission #640576

#TimeUsernameProblemLanguageResultExecution timeMemory
640576socpitePaprike (COI18_paprike)C++14
100 / 100
46 ms17620 KiB
#include<bits/stdc++.h>
using namespace std;
 
#define f first 
#define s second 
 
typedef long long ll;
typedef long double ld;

const int maxn = 1e5+5;
const int mod = 1e9+7;

vector<int> tree[maxn];

int n, ans;
ll k;

ll d[maxn];

void dfs(int x, int p){
    vector<ll> vec;
    for(auto v: tree[x]){
        if(v==p)continue;
        dfs(v, x);
        vec.push_back(d[v]);
    }
    sort(vec.begin(), vec.end());
    for(auto v: vec){
        if(d[x]+v > k)break;
        d[x]+=v;
        ans--;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    ans = n-1;
    for(int i = 1; i <= n; i++)cin >> d[i];
    for(int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs(1, 0);
    cout << ans;
}

/*
1 3 5 4 2
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...