#include #include #include #include #include #include #include using namespace std; typedef long long ll; const int N_MAX = 500000; int M; bool used[N_MAX]; int idx[N_MAX]; vector vs; vector buf; vector G[N_MAX]; vector G_inv[N_MAX]; vector> ans; void clear(){ for(int i = 0; i < M; i++) used[i] = false; } void dfs1(int v){ used[v] = true; for(int i = 0; i < G[v].size(); i++){ if(!used[G[v][i]]) dfs1(G[v][i]); } vs.push_back(v); } void dfs2(int v, int k){ used[v] = true; idx[v] = k; for(int i = 0; i < G_inv[v].size(); i++){ if(!used[G_inv[v][i]]) dfs2(G_inv[v][i], k); } buf.push_back(v); } void scc(){ for(int i = 0; i < M; i++){ if(!used[i]) dfs1(i); } clear(); int cur = 0; for(int i = vs.size()-1; i >= 0; i--){ if(!used[vs[i]]) { dfs2(vs[i], cur); cur++; ans.push_back(buf); buf.clear(); } } } int N; int S[500], T[500], U[500]; int index(int i, int j, bool b){ if(!b) return i*N+j; else return i*N+j+N*N; } void create_inv(){ for(int v = 0; v < M; v++){ for(int to : G[v]){ G_inv[to].push_back(v); } } } int a[500][500]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N; M = 2*N*N; for(int i = 0; i < N; i++) { cin >> S[i]; S[i]--; } for(int i = 0; i < N; i++) { cin >> T[i]; T[i]--; } for(int i = 0; i < N; i++) cin >> U[i]; for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ if(U[i] == 0){ // a or b i.e. !a => b & !b => a G[index(S[i], j, false)].push_back(index(j, T[i], true)); G[index(j, T[i], false)].push_back(index(S[i], j, true)); } if(U[i] == 1){ // !a or b i.e. a => b & !b => !a G[index(S[i], j, true)].push_back(index(j, T[i], true)); G[index(j, T[i], false)].push_back(index(S[i], j, false)); } if(U[i] == 2){ // a or !b i.e. !a => !b & b => a G[index(S[i], j, false)].push_back(index(j, T[i], false)); G[index(j, T[i], true)].push_back(index(S[i], j, true)); } if(U[i] == 3){ // !a or !b i.e. a => !b & b => !a G[index(S[i], j, true)].push_back(index(j, T[i], false)); G[index(j, T[i], true)].push_back(index(S[i], j, false)); } } } create_inv(); scc(); for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ // cout << idx[index(i, j, false)] << ' ' << idx[index(i, j, true)] << endl; if(idx[index(i, j, false)] == idx[index(i, j, true)]){ cout << -1 << endl; return 0; }else if(idx[index(i, j, false)] < idx[index(i, j, true)]){ a[i][j] = 1; }else{ a[i][j] = 0; } } } for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ cout << a[i][j] << ' '; } cout << endl; } for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ if(a[S[i]][j]+a[j][T[i]]*2 ==U[i]) cout << "NG" << endl; } } }