Language: C++

#include <bits/stdc++.h>
#define N 200005
 
using namespace std;
typedef pair <int,int> P;
 
vector <int> vec[N];
int par[N],dep[N];
int pr[N],ng[N];
bool use[N];
int n;
 
int rev(int v)
{
	if(v>=n) return v-n;
	return v+n;
}
int dfs(int v,int d)
{
	dep[v]=d;
	int a=-1;
	for(int i=0;i<vec[v].N();i++)
	{
		int to=vec[v][i];
		int tg=dfs(to,d+1);
		if(tg!=-1)
		{
			if(a==-1) a=tg;
			else
			{
				//printf("%d %d\n",a,tg);
				pr[a]=tg;
				pr[tg]=a;
				a=-1;
			}
		}
	}
	if(a==-1) a=v;
	return a;
}
int LCA(int a,int b)
{
	while(a!=b)
	{
		if(dep[a]>dep[b]) swap(a,b);
		b=par[b];
	}
	return a;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<2*n;i++)
	{
		int p;
		scanf("%d",&p);p--;
		if(p<0) p=2*n;
		else if(i>=n) p+=n;
		par[i]=p;
		vec[p].push_back(i);
	}
	for(int i=0;i<n;i++)
	{
		if(vec[i].N()%2!=vec[i+n].N()%2)
		{
			puts("IMPOSSIBLE");
			return 0;
		}
	}
	memset(pr,-1,Nof(pr));
	dfs(2*n,0);
	for(int i=0;i<2*n;i++)
	{
		if(!use[i]&&pr[i]!=-1)
		{
			use[i]=true;
			int now=i;
			do
			{
				use[now]=true;
				int to=pr[now];
				int p=LCA(now,to);
				for(int j=now;j!=p;j=par[j]) ng[j]=1;
				for(int j=to;j!=p;j=par[j]) ng[j]=-1;
				now=rev(to);
			}while(now!=i);
		}
	}
	puts("POSSIBLE");
	for(int i=0;i<n;i++)
	{
		int ret=ng[i];
		for(int j=0;j<vec[i].N();j++)
		{
			int to=vec[i][j];
			ret-=ng[to];
		}
		if(i!=0) printf(" ");
		printf("%d",ret);
	}puts("");
	return 0;
}

Compiler output:
a.cc: In function 'int dfs(int, int)':
a.cc:2:11: error: expected unqualified-id before numeric constant
    2 | #define N 200005
      |           ^~~~~~
a.cc:22:30: note: in expansion of macro 'N'
   22 |         for(int i=0;i<vec[v].N();i++)
      |                              ^
a.cc:22:30: error: expected ';' before numeric constant
   22 |         for(int i=0;i<vec[v].N();i++)
      |                              ^
      |                              ;
a.cc:22:31: error: expression cannot be used as a function
   22 |         for(int i=0;i<vec[v].N();i++)
      |                               ^
a.cc:22:33: error: expected ')' before ';' token
   22 |         for(int i=0;i<vec[v].N();i++)
      |            ~                    ^
      |                                 )
a.cc:22:34: error: 'i' was not declared in this scope
   22 |         for(int i=0;i<vec[v].N();i++)
      |                                  ^
a.cc: In function 'int main()':
a.cc:2:11: error: expected unqualified-id before numeric constant
    2 | #define N 200005
      |           ^~~~~~
a.cc:64:27: note: in expansion of macro 'N'
   64 |                 if(vec[i].N()%2!=vec[i+n].N()%2)
      |                           ^
a.cc:64:27: error: expected ')' before numeric constant
   64 |                 if(vec[i].N()%2!=vec[i+n].N()%2)
      |                   ~       ^
      |                           )
a.cc:70:22: error: 'Nof' was not declared in this scope
   70 |         memset(pr,-1,Nof(pr));
      |                      ^~~
a.cc:2:11: error: expected unqualified-id before numeric constant
    2 | #define N 200005
      |           ^~~~~~
a.cc:93:38: note: in expansion of macro 'N'
   93 |                 for(int j=0;j<vec[i].N();j++)
      |                                      ^
a.cc:93:38: error: expected ';' before numeric constant
   93 |                 for(int j=0;j<vec[i].N();j++)
      |                                      ^
      |                                      ;
a.cc:93:39: error: expression cannot be used as a function
   93 |                 for(int j=0;j<vec[i].N();j++)
      |                                       ^
a.cc:93:41: error: expected ')' before ';' token
   93 |                 for(int j=0;j<vec[i].N();j++)
      |                    ~                    ^
      |                                         )
a.cc:93:42: error: 'j' was not declared in this scope
   93 |                 for(int j=0;j<vec[i].N();j++)
      |                                          ^