Language: C++

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <unordered_map>
#include <map>
#include <bitset>
#include <string>
#include <cstring>

#define pb push_back
#define mp make_pair
#define l(x) x << 1
#define r(x) x << 1 | 1
#define scan(x) do {while((x=getchar())<'0') ; for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0') ; } while(0)
char _;
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<float, float> pff;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

int N, x[1005], u;
ll dp1[1005], dp2[1005][5005];
vector<int> adj[1005];

ll go2(int i, int j, int k) {
    if (adj[i].size() <= j) {
        return 0;
    }
    if (dp2[j][k] != -1) {
        return dp2[j][k];
    }

    u = adj[i][j];
    ll ret = 1 << 30;
    if (k + dp1[u] <= x[i]) {
        ret = min(ret, go2(i, j + 1, k + dp1[u]) + x[u]);
    }
    if (k + x[u] <= x[i]) {
        ret = min(ret, go2(i, j + 1, k + x[u]) + dp1[u]);
    }
    return dp2[j][k] = ret;
}

ll go1(int i, int p) {
    if (adj[i].empty()) {
        return dp1[i] = 0;
    }
    if (dp1[i] != -1) {
        return dp1[i];
    }

    for (int j = 0; j < adj[i].size(); j++) {
        u = adj[i][j];
        if (adj[i][j] == p) continue;
        go1(adj[i][j], i);
        for (int k = x[i]; k <= x[i]; k++) {
            if (k - x[u] >= 0) {
                dp2[k] = min(dp2[k], dp2[k - x[u]] + dp2[u]);
            }
            if (k - dp1[u] >= 0) {
                dp2[k] = min(dp2[k], dp2[k - dp1[u]] + x[u]);
            }
        }
    }

    memset(dp2, -1, sizeof dp2);
    return dp1[i] = go2(i, 0, 0);
}

int main() {
    scanf("%d", &N);
    for (int i = 2; i <= N; i++) {
        scanf("%d", &u);
        adj[u].pb(i);
    }
    for (int i = 1; i <= N; i++) {
        scanf("%d", &x[i]);
    }
    memset(dp1, -1, sizeof dp1);
    printf("%s\n", go1(1, 1) < 1 << 30 ? "POSSIBLE" : "IMPOSSIBLE");
}


Compiler output:
a.cc: In function 'll go1(int, int)':
a.cc:73:52: error: invalid operands of types 'll [5005]' {aka 'long long int [5005]'} and 'll [5005]' {aka 'long long int [5005]'} to binary 'operator+'
   73 |                 dp2[k] = min(dp2[k], dp2[k - x[u]] + dp2[u]);
      |                                      ~~~~~~~~~~~~~ ^ ~~~~~~
      |                                                  |        |
      |                                                  |        ll [5005] {aka long long int [5005]}
      |                                                  ll [5005] {aka long long int [5005]}
a.cc:76:29: error: no matching function for call to 'min(ll [5005], ll*)'
   76 |                 dp2[k] = min(dp2[k], dp2[k - dp1[u]] + x[u]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:76:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int [5005]' and 'll*' {aka 'long long int*'})
   76 |                 dp2[k] = min(dp2[k], dp2[k - dp1[u]] + x[u]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:76:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'll*' {aka 'long long int*'}
   76 |                 dp2[k] = min(dp2[k], dp2[k - dp1[u]] + x[u]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~