Submission #1293838

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

/*
      ---===ASCII help===---
     '0' -> 48     '9' -> 57
     'A' -> 65     'Z' -> 90
     'a' -> 97     'z' -> 122
*/

const long long mod = 1e9 + 7;
static const int MAXN = 300000 + 5;

int n;
long long k;
long long h[MAXN];
vector<vector<int>> g;
long long sub[MAXN];
long long cuts = 0;

void dfs(int u, int parent) {
    long long sum = h[u];
    for (int v : g[u]) {
        if (v == parent) continue;
        dfs(v, u);
        if (sum + sub[v] <= k) sum += sub[v];
        else cuts++;
    }
    sub[u] = sum;
}

void solve() {
    cin >> n >> k;
    g.assign(n + 1);
    for (int i = 1; i <= n; i++) cin >> h[i];
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1, -1);
    cout << cuts;
}

int main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message (stderr)

paprike.cpp: In function 'void solve()':
paprike.cpp:34:13: error: no matching function for call to 'std::vector<std::vector<int> >::assign(int)'
   34 |     g.assign(n + 1);
      |     ~~~~~~~~^~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from paprike.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:828:9: note: candidate: 'template<class _InputIterator, class> constexpr void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]'
  828 |         assign(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:828:9: note:   template argument deduction/substitution failed:
paprike.cpp:34:13: note:   candidate expects 2 arguments, 1 provided
   34 |     g.assign(n + 1);
      |     ~~~~~~~~^~~~~~~
/usr/include/c++/13/bits/stl_vector.h:808:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; size_type = long unsigned int; value_type = std::vector<int>]'
  808 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:808:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/13/bits/stl_vector.h:855:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]'
  855 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:855:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::vector<int> >'
  855 |       assign(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~