Language: C++

//
// Created by kapildd on 10/5/17.
//
#include <bits/stdc++.h>
#define MAX_X 5010
#define MAX_VAL (1e9)
using namespace std;

int dfs(int v, int parent, vector< vector<int> >& adj, vector<int>& X) {
    vector<long long> dp(MAX_X, MAX_VAL);
    vector<long long> extra(MAX_X, MAX_VAL);
    dp[0] = 0;
    for(int i=0; i<adj[v].size(); i++) {
        int u = adj[v][i];
        if(u == parent) continue;
        int white = dfs(u, v, adj, X);
        if(white==MAX_VAL) continue;
        fill(extra.begin(), extra.end(), MAX_VAL);
        for(int j = 0; j<MAX_X-white; j++) {
            extra[j+white] = min(extra[j+white], dp[j]+X[u]);
        }
        for(int j=0; j<MAX_X-X[u]; j++) {
            extra[j+X[u]] = min(extra[j+X[u]], dp[j]+white);
        }
        swap(extra, dp);
    }
    int min_w = MAX_VAL;
    for(int i=0; i<=X[v]; i++) {
        min_w = min(min_w, dp[i]);
    }
    return min_w;
}

int main() {
    int n;
    cin>>n;
    vector<int> parent(n+1, 0), X(n+1);
    vector< vector<int> > adj(n+1);
    for(int i=2; i<=n; i++) {
        cin>>parent[i];
        adj[parent[i]].push_back(i);
    }
    for(int i=1; i<=n; i++) {
        cin>>X[i];
    }
    string ans = "IMPOSSIBLE";
    int cval = dfs(1, 0, adj, X);
    if(cval < MAX_VAL)
        ans = "POSSIBLE";
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int dfs(int, int, std::vector<std::vector<int> >&, std::vector<int>&)':
a.cc:29:20: error: no matching function for call to 'min(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
   29 |         min_w = min(min_w, dp[i]);
      |                 ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:4:
/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:29:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   29 |         min_w = min(min_w, dp[i]);
      |                 ~~~^~~~~~~~~~~~~~
/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:29:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   29 |         min_w = min(min_w, dp[i]);
      |                 ~~~^~~~~~~~~~~~~~