Submission #1117820

#TimeUsernameProblemLanguageResultExecution timeMemory
1117820vjudge1Paprike (COI18_paprike)C++17
13 / 100
31 ms11016 KiB
// Author RufatM
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e9+7
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define pb push_back
#define pii pair<ll,int>
#define all(a) a.begin(),a.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int MAXN = 100005;
vector<int> tree[MAXN];
int h[MAXN];
int k;
int cuts = 0;
int dfs(int u, int parent) {
    int total_spice = h[u];
    for (int v : tree[u]) {
        if (v != parent) {
            int child_spice = dfs(v, u);
            if (total_spice + child_spice <= k) {
                total_spice += child_spice;
            } else {
                cuts++;
            }
        }
    }
    return total_spice;
}
signed main(){
    fastio;
    int t=1;
    //cin >> t;
    while(t--){
    int n;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < n -1; i++) {
        int u, v;
        cin >> u >> v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }

    dfs(1, 0);
    cout << cuts << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...