#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) templateostream& operator<<(ostream& os,const pair&a){return os<<"("<void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<void chmin(T&a,const T&b){if(a>b)a=b;} templatevoid chmax(T&a,const T&b){if(a> g, r; TwoSAT(int N): N(N) { g = vector>(2*N); r = vector>(2*N); } // (a == a_val || b == b_val) void add_cond(int a, bool a_val, int b, bool b_val) { int x = 2 * a + (a_val ? 1 : 0); int y = 2 * b + (b_val ? 1 : 0); g[x^1].push_back(y); g[y^1].push_back(x); r[y].push_back(x^1); r[x].push_back(y^1); } // !(a == a_val && b == b_val) void add_forbid(int a, bool a_val, int b, bool b_val) { add_cond(a, !a_val, b, !b_val); } vector sccid; int sccnum; void dfs(int p, vector& order) { if (sccid[p] != 0) return; sccid[p] = 1; for (int i : g[p]) dfs(i, order); order.push_back(p); } void rdfs(int p, int id) { if (sccid[p] != -1) return; sccid[p] = id; for (int i : r[p]) rdfs(i, id); } void scc() { sccnum = 0; sccid = vector(2 * N); vector order; REP(i, 2*N) dfs(i, order); fill(ALL(sccid), -1); sccnum = 0; for (int i = (int)order.size() - 1; i >= 0; i--) if (sccid[order[i]] == -1) { rdfs(order[i], sccnum); sccnum++; } } // 割り当てを一つ返す。存在しない場合は長さ0を返す。 vector solve() { vector res(N); REP(i, N) { if (sccid[2*i] != -1 && sccid[2*i] == sccid[2*i+1]) return {}; res[i] = sccid[2*i+1] > sccid[2*i] ? 1 : 0; } return res; } }; const int MAX_N = 505; int A[MAX_N][MAX_N]; int N; int nodeId(int r, int c) { return (r * N + c); } int main2() { N = nextLong(); vector S(N), T(N), U(N); REP(i, N) S[i] = nextLong()-1; REP(i, N) T[i] = nextLong()-1; REP(i, N) U[i] = nextLong(); TwoSAT twoSAT(N*N); REP(i, N) REP(j, N) { twoSAT.add_forbid(nodeId(S[i], j), U[i] & 1, nodeId(j, T[i]), U[i] >> 1); } twoSAT.scc(); auto res = twoSAT.solve(); if (res.size() == 0) { cout << -1 << endl; } else { REP(i, N*N) { int r = i / N; int c = i % N; A[r][c] = res[i]; } REP(r, N) { REP(c, N) { if (c) cout << ' '; cout << A[r][c]; } cout << '\n'; } } return 0; } int main() { #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }