Language: C++

#include <bits/stdc++.h>
#define int long long
using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct edge
{
	int v,next;
}vs[2010];
int st[2010],ee,n,val[2010],Fs[2010];
int wss[2010][6010],tmp[6010],fg;
inline void addedge(int u,int v)
{
	vs[++ee].v=v;vs[ee].next=st[u];st[u]=ee;
}
inline void dfs(int rt)
{
	memset(wss[rt],-1,sizeof wss[rt]);
	wss[rt][0]=0;
	for(int i=st[rt];i;i=vs[i].next)
	{
		dfs(vs[i].v); 
		if(fg==1) return ;
		int v=vs[i].v;
		memset(tmp,-1,sizeof tmp);
		for(int i=5000;i>=val[v];i--) if(wss[rt][i-val[v]]!=-1)
		{
			if(tmp[i]==-1) tmp[i]=wss[rt][i-val[v]]+Fs[v];
			else tmp[i]=min(tmp[i],wss[rt][i-val[v]]+Fs[v]);
		}
		for(int i=5000;i>=Fs[v];i--) if(wss[rt][i-Fs[v]]!=-1)
		{
			if(tmp[i]==-1) tmp[i]=wss[rt][i-Fs[v]]+val[v];
			else tmp[i]=min(tmp[i],wss[rt][i-Fs[v]]+val[v]);
		}
		for(int i=0;i<=5000;i++) wss[rt][i]=tmp[i];
	}
	//for(int i=0;i<=10;i++) printf("%d ",wss[rt][i]); printf("\n");
	Fs[rt]=0x3fffffff;
	for(int i=0;i<=min(val[rt],5000);i++) if(wss[rt][i]!=-1)
		Fs[rt]=min(Fs[rt],wss[rt][i]);
	if(Fs[rt]==0x3fffffff) fg=1;
}
signed main()
{
	n=read(); for(int i=2;i<=n;i++)
	{
		int k=read(); addedge(k,i);
	}
	for(int i=1;i<=n;i++) val[i]=read();
	dfs(1);
	if(fg) puts("IMPOSSIBLE");
	else puts("POSSIBLE");
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(long long int)':
a.cc:46:27: error: no matching function for call to 'min(long long int&, int)'
   46 |         for(int i=0;i<=min(val[rt],5000);i++) if(wss[rt][i]!=-1)
      |                        ~~~^~~~~~~~~~~~~~
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: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:46:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   46 |         for(int i=0;i<=min(val[rt],5000);i++) if(wss[rt][i]!=-1)
      |                        ~~~^~~~~~~~~~~~~~
/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:46:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   46 |         for(int i=0;i<=min(val[rt],5000);i++) if(wss[rt][i]!=-1)
      |                        ~~~^~~~~~~~~~~~~~