#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; struct TwoSatLight { TwoSatLight(int n) : n(n), graph(n << 1), rev_graph(n << 1), used(n << 1, false), id(n << 1, -1) {} int negate(int x) { return (n + x) % (n << 1); } void add_or(int x, int y) { graph[negate(x)].emplace_back(y); graph[negate(y)].emplace_back(x); rev_graph[y].emplace_back(negate(x)); rev_graph[x].emplace_back(negate(y)); } void add_if(int x, int y) { add_or(negate(x), y); } void add_nand(int x, int y) { add_or(negate(x), negate(y)); } void set_true(int x) { add_or(x, x); } void set_false(int x) { set_true(negate(x)); } vector build() { REP(i, n << 1) { if (!used[i]) dfs(i); } int now = 0; for (int i = (n << 1) - 1; i >= 0; --i) { if (id[order[i]] == -1) rev_dfs(order[i], now++); } vector res(n); REP(i, n) { if (id[i] == id[negate(i)]) return {}; res[i] = id[negate(i)] < id[i]; } return res; } private: int n; vector> graph, rev_graph; vector used; vector id, order; void dfs(int ver) { used[ver] = true; for (int e : graph[ver]) { if (!used[e]) dfs(e); } order.emplace_back(ver); } void rev_dfs(int ver, int now) { id[ver] = now; for (int e : rev_graph[ver]) { if (id[e] == -1) rev_dfs(e, now); } } }; int main() { 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]; TwoSatLight two_sat(n * n); REP(i, n) REP(j, n) { int x = s[i] * n + j, y = j * n + t[i]; if (u[i] == 0) { two_sat.add_or(x, y); } else if (u[i] == 1) { two_sat.add_if(x, y); } else if (u[i] == 2) { two_sat.add_if(y, x); } else if (u[i] == 3) { two_sat.add_or(two_sat.negate(x), two_sat.negate(y)); } } vector ans = two_sat.build(); if (ans.empty()) { cout << "-1\n"; return 0; } int pos = 0; REP(i, n) REP(j, n) cout << ans[pos++] << " \n"[j + 1 == n]; return 0; }