Language: C++

#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (1002)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n,A[MAXN],dp[MAXN][5002],pdp[MAXN][5002];
vector<int>v[MAXN];
void no(){ cout<<"IMPOSSIBLE"<<'\n'; exit(0); }
void dfs(ll x,ll p){
	fill(dp[x],dp[x]+5002,LLINF);
	bool f=0;ll sum=0;
	for(auto i:v[x])if(i!=p){
		dfs(i,x);
		ll a=A[i],b=dp[i][A[i]];sum+=a+b;
		if(min(a,b)>A[x])no();
		if(f==0){
			if(a<=A[x])dp[x][a]=b;if(b<=A[x])dp[x][b]=a;
		}else{
			for(ll i=A[x];i>=0;--i){
				if(i-a>=0)dp[x][i]=min(dp[x][i],pdp[x][i-a]+b);
				if(i-b>=0)dp[x][i]=min(dp[x][i],pdp[x][i-b]+a);
			}
		}f=1;
		FOR(i,0,A[x]+1){
			pdp[x][i]=dp[x][i];
		}
		fill(dp[x],dp[x]+5002,LLINF);
	}
	pi xx=pi(LLINF,LLINF);
	FOR(i,0,A[x]+1){
		dp[x][i]=pdp[x][i];
		xx=min(x,pi(dp[x][i],i));
	}
	assert(xx.f+xx.s==sum);
	FOR(i,1,A[x]+1){
		dp[x][i]=min(dp[x][i],dp[x][i-1]);
	}
	if(dp[x][A[x]]>=LLINF)no();
}
int main()
{
	FAST
	cin>>n;
	FOR(i,2,n+1){
		ll a;cin>>a;v[i].pb(a);v[a].pb(i);
	}
	FOR(i,1,n+1)cin>>A[i];
	dfs(1,1);
	cout<<"POSSIBLE\n";
}


Compiler output:
a.cc: In function 'void dfs(long long int, long long int)':
a.cc:66:23: error: no matching function for call to 'min(long long int&, pi)'
   66 |                 xx=min(x,pi(dp[x][i],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:2:
/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:66:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'pi' {aka 'std::pair<long long int, long long int>'})
   66 |                 xx=min(x,pi(dp[x][i],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:66:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   66 |                 xx=min(x,pi(dp[x][i],i));
      |                    ~~~^~~~~~~~~~~~~~~~~~