Submission #1117678

#TimeUsernameProblemLanguageResultExecution timeMemory
1117678vjudge1Paprike (COI18_paprike)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

#define SPEED ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define ALL(x) x.begin(), x.end()
#define intt long long
#define pb push_back
#define endl "\n"

const int sz = 1e5 + 5;

intt n, k, ans = 0;
vector<vector<intt>>graph;
vector<intt> val(sz), subsize(sz, 0);
s
void dfs(intt node, intt parent, intt k) {
    vector<intt>subtree;
    subsize[node] = val[node];
    for(auto u : graph[node]) {
        if(parent != u) {
            dfs(u, node, k);
            subsize[node] += subsize[u];
            subtree.pb(subsize[u]);
        }
    }
    sort(ALL(subtree));
    reverse(ALL(subtree));
    for(int i = 0; i < (int)subtree.size(); i++) {
        if(subsize[node] > k) {
            subsize[node] -= subtree[i];
            ans++;
        } else{
            break;
        }
    }
}

void solve() {
    cin >> n >> k;
    graph.resize(n+1);
    val.resize(n + 1);
    for(int  i = 1; i <= n; i++) {
        cin >> val[i];
    }

    for(int i = 1; i <= n - 1; i++) {
        intt a, b;
        cin >> a >> b;
        graph[a].pb(b);
        graph[b].pb(a);
    }

    dfs(1, -1, k);
    cout <<  ans << endl;
}

int main() {
    SPEED;
    intt tst = 1;
    // cin >> tst;
    while (tst--) {
        solve();
    }
}

Compilation message (stderr)

paprike.cpp:15:1: error: 's' does not name a type
   15 | s
      | ^
paprike.cpp: In function 'void solve()':
paprike.cpp:53:5: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
   53 |     dfs(1, -1, k);
      |     ^~~
      |     ffs