#pragma GCC optimize("Ofast") #include #include #include using namespace std; using namespace __gnu_pbds; using ll = long long; using ull = unsigned long long; using pii = pair; using pll = pair; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() constexpr char ln = '\n'; constexpr long long MOD = 1000000007; //constexpr long long MOD = 998244353; template inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; } template inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; } inline int popcount(int x) {return __builtin_popcount(x);} inline int popcount(long long x) {return __builtin_popcountll(x);} void print() { cout << "\n"; } template void print(const T &x, const Args &... args) { cout << x << " "; print(args...); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// struct StronglyConnectedComponent { //T:強連結成分をトポロジカルソートしたグラフ C:強連結成分の内訳 vector> G,R,T,C; vector vs,used,blg; StronglyConnectedComponent() {} StronglyConnectedComponent(int N) : G(N), R(N), used(N), blg(N) {} void add_edge(int u,int v) { G[u].emplace_back(v); R[v].emplace_back(u); } void dfs(int v){ used[v] = 1; for(int u:G[v]) { if(!used[u]) dfs(u); } vs.emplace_back(v); } void rdfs(int v, int k) { used[v] = 1; blg[v] = k; C[k].emplace_back(v); for(int u:R[v]) { if(!used[u]) rdfs(u,k); } } int build() { int N = G.size(); for(int v = 0; v < N; v++) { if(!used[v]) dfs(v); } fill(used.begin(),used.end(),0); int k = 0; for(int i = N-1; i >= 0; i--) { if(!used[vs[i]]) { T.emplace_back(); C.emplace_back(); rdfs(vs[i], k++); } } for(int v = 0; v < N; v++) { for(int u:G[v]) { if(blg[v] != blg[u]) T[blg[v]].emplace_back(blg[u]); } } for(int i = 0; i < k; i++) { sort(T[i].begin(),T[i].end()); T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end()); } return k; } int operator[](int k) const{return blg[k];} }; struct TwoSat { int N; StronglyConnectedComponent scc; TwoSat(int N) : N(N), scc(N*2) {} int negate(int v) {return (N+v)%(N*2);} void add_if(int u, int v) { // u -> v <=> !v -> !u scc.add_edge(u,v); scc.add_edge(negate(v),negate(u)); } void add_or(int u, int v) { // u or v <=> !u -> v add_if(negate(u),v); } void add_nand(int u, int v) { // u nand v <=> u -> !v add_if(u,negate(v)); } void set_true(int v) { // v <=> !v -> v scc.add_edge(negate(v),v); } void set_false(int v) { // !v <=> v -> !v scc.add_edge(v,negate(v)); } vector build() { scc.build(); vector ret(N); for (int i = 0; i < N; ++i) { if(scc[i]==scc[N+i]) return {}; ret[i] = scc[i] > scc[N+i]; } return ret; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector S(N),T(N),U(N); rep(i,N) cin >> S[i], --S[i]; rep(i,N) cin >> T[i], --T[i]; rep(i,N) cin >> U[i]; TwoSat TS(N*N); rep(i,N) { rep(j,N) { if (U[i]==0) { TS.add_nand(N*N+S[i]*N+j,N*N+j*N+T[i]); } else if (U[i]==1) { TS.add_nand(S[i]*N+j,N*N+j*N+T[i]); } else if (U[i]==2) { TS.add_nand(N*N+S[i]*N+j,j*N+T[i]); } else { TS.add_nand(S[i]*N+j,j*N+T[i]); } } } auto ans = TS.build(); if (ans.empty()) cout << -1 << ln; else { rep(i,N*N) { cout << ans[i] << " "; if ((i+1)%N==0) cout << ln; } } }