#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[MAX_V]; vector r[MAX_V]; const int MAX_N = 505; int A[MAX_N][MAX_N]; int N; int nodeId(int r, int c, int f) { return (r * N + c) * 2 + f; } int sccid[MAX_V]; 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() { vector order; CLR(sccid, 0); REP(i, N) dfs(i, order); CLR(sccid, -1); sccnum = 0; for (int i = (int)order.size() - 1; i >= 0; i--) if (sccid[order[i]] == -1) { rdfs(order[i], sccnum); sccnum++; } } int main2() { REP(i, MAX_V) g[i].clear(); REP(i, MAX_V) r[i].clear(); 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(); REP(i, N) REP(j, N) { int a, b; if (U[i] == 0) { a = nodeId(S[i], j, 0); b = nodeId(j, T[i], 0); } if (U[i] == 1) { a = nodeId(S[i], j, 1); b = nodeId(j, T[i], 0); } if (U[i] == 2) { a = nodeId(S[i], j, 0); b = nodeId(j, T[i], 1); } if (U[i] == 3) { a = nodeId(S[i], j, 1); b = nodeId(j, T[i], 1); } g[a^1].push_back(b); g[b^1].push_back(a); r[b].push_back(a^1); r[a].push_back(b^1); } scc(); // REP(i, N*N) cout << sccid[i * 2] << " "; cout << endl; // REP(i, N*N) cout << sccid[i * 2 + 1] << " "; cout << endl; bool ng = false; REP(i, N*N) { if (sccid[i * 2] != -1 && sccid[i * 2] == sccid[i * 2 + 1]) { ng = true; } } if (ng) { cout << -1 << endl; } else { REP(i, N*N) { int r = i / N; int c = i % N; A[r][c] = (sccid[i * 2 + 1] < sccid[i * 2]) ? 1 : 0; } 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; }