Language: C++

#include<bits/stdc++.h>
#include<vector>
#define N 200005
using namespace std;
vector<int> G[N];
int n,m=1,a[N],b[N],head[N],next[2*N],num[2*N],vis[2*N],op[N],dex[2*N],X[N],rt;
void link(int x,int y,int z)
{
	num[++m]=y,dex[m]=z,next[m]=head[x],head[x]=m;
	num[++m]=x,dex[m]=z,next[m]=head[y],head[y]=m;
}
void dfs(int t)
{
	int i;
	for(i=head[t];i;i=next[i]){
		if(vis[i]|vis[i^1]) continue;
		vis[i]=vis[i^1]=1;
		dfs(num[i]);
		if(i&1) X[dex[i]]=1; else X[dex[i]]=-1;
	  }
}
void DFS(int t)
{
	int i;
	for(i=0;i<G[t].size();i++)
		X[t]-=X[G[t][i]],DFS(G[t][i]);
}
int main()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	for(i=1;i<=n;i++) scanf("%d",&b[i]);
	
	for(i=1;i<=n;i++){
		if(a[i]!=-1) G[a[i]].push_back(i); else rt=i;
		link(i,a[i]==-1 ? n+1 : a[i],i);
		link(b[i]==-1 ? n+1 : b[i],i,i);
		if(a[i]>0) op[a[i]]^=1;
		if(b[i]>0) op[b[i]]^=1;
	  }
	for(i=1;i<=n;i++)
		if(op[i]){
			printf("IMPOSSIBLE");
			return 0;
		  }
	dfs(1);
	DFS(rt);
	printf("POSSIBLE\n");
	for(i=1;i<=n;i++)
		printf("%d ",X[i]);
	return 0;
}


Compiler output:
a.cc: In function 'void link(int, int, int)':
a.cc:9:29: error: reference to 'next' is ambiguous
    9 |         num[++m]=y,dex[m]=z,next[m]=head[x],head[x]=m;
      |                             ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 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_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:6:29: note:                 'int next [400010]'
    6 | int n,m=1,a[N],b[N],head[N],next[2*N],num[2*N],vis[2*N],op[N],dex[2*N],X[N],rt;
      |                             ^~~~
a.cc:10:29: error: reference to 'next' is ambiguous
   10 |         num[++m]=x,dex[m]=z,next[m]=head[y],head[y]=m;
      |                             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:6:29: note:                 'int next [400010]'
    6 | int n,m=1,a[N],b[N],head[N],next[2*N],num[2*N],vis[2*N],op[N],dex[2*N],X[N],rt;
      |                             ^~~~
a.cc: In function 'void dfs(int)':
a.cc:15:27: error: reference to 'next' is ambiguous
   15 |         for(i=head[t];i;i=next[i]){
      |                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:6:29: note:                 'int next [400010]'
    6 | int n,m=1,a[N],b[N],head[N],next[2*N],num[2*N],vis[2*N],op[N],dex[2*N],X[N],rt;
      |                             ^~~~