#include #define rep(i,n) for(ll i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int n = 250005; int c = 0; vector> graph(2*n,vector()); vector> revgraph(2*n,vector()); vector seen(2*n,false); vector postorder; vector sccgroup(2*n,-1); void dfs(int i){ seen[i] = true; for(int v:graph[i]){ if(seen[v]) continue; dfs(v); } postorder.push_back(i); } void revdfs(int i){ sccgroup[i] = c; seen[i] = true; for(int v:revgraph[i]){ if(seen[v]) continue; revdfs(v); } } void scc(){ for(int i=0;i<2*n;i++){ if(!seen[i]) dfs(i); } rep(i,2*n) seen[i] = false; for(int i=2*n-1;i>=0;i--){ if(!seen[postorder[i]]){ revdfs(postorder[i]); ++c; } } } vector sat(){ rep(i,n){ if(sccgroup[i] == sccgroup[i+n]){ return {}; } } vector res(n,false); rep(i,n){ if(sccgroup[i] > sccgroup[i+n]) res[i] = true; } return res; } int main(){ int m; cin >> m; n = m * m; vector s(m),t(m),u(m); rep(i,m) cin >> s[i], --s[i]; rep(i,m) cin >> t[i], --t[i]; rep(i,m) cin >> u[i]; rep(i,m){ rep(j,m){ int p = s[i] * m + j,q = j * m + t[i]; if(u[i]==0){ graph[p+n].push_back(q); graph[q+n].push_back(p); revgraph[p].push_back(q+n); revgraph[q].push_back(p+n); }else if(u[i]==1){ graph[p].push_back(q); graph[q+n].push_back(p+n); revgraph[p+n].push_back(q+n); revgraph[q].push_back(p); }else if(u[i]==2){ graph[p+n].push_back(q+n); graph[q].push_back(p); revgraph[p].push_back(q); revgraph[q+n].push_back(p+n); }else{ graph[p].push_back(q+n); graph[q].push_back(p+n); revgraph[p+n].push_back(q); revgraph[q+n].push_back(p); } } } scc(); vector SAT = sat(); if(SAT.size() == 0){ cout << -1 << endl; return 0; } rep(i,n){ cout << SAT[i] << " "; if(i%m==m-1) cout << endl; } /* rep(i,m)rep(j,m){ if(SAT[s[i]*m+j] + SAT[j*m+t[i]] == u[i]){ assert(false); } } */ return 0; }