#include #include template struct Edge { int src, dst; Cost cost; Edge(int src = -1, int dst = -1, Cost cost = 1) : src(src), dst(dst), cost(cost){}; bool operator<(const Edge& e) const { return this->cost < e.cost; } bool operator>(const Edge& e) const { return this->cost > e.cost; } }; template struct Graph { std::vector>> graph; Graph(int n = 0) : graph(n) {} void span(bool direct, int src, int dst, Cost cost = 1) { graph[src].emplace_back(src, dst, cost); if (!direct) graph[dst].emplace_back(dst, src, cost); } int size() const { return graph.size(); } void clear() { graph.clear(); } void resize(int n) { graph.resize(n); } std::vector>& operator[](int v) { return graph[v]; } std::vector> operator[](int v) const { return graph[v]; } }; template struct StronglyConnectedComponents { Graph graph, rgraph; std::vector visited; std::vector stk; // id[v] = 頂点vはgroups[id[v]]に属する std::vector id; std::vector> groups; explicit StronglyConnectedComponents(const Graph& g) : graph(g), visited(graph.size(), false), id(graph.size(), -1) { revinit(); for (int v = 0; v < (int)graph.size(); ++v) dfs(v); while (!stk.empty()) { int v = stk.back(); stk.pop_back(); if (id[v] < 0) { groups.emplace_back(); rdfs(v); } } } void revinit() { rgraph = Graph(graph.size()); for (int v = 0; v < (int)graph.size(); ++v) { for (const auto& e : graph[v]) { rgraph[e.dst].emplace_back(e.dst, v, e.cost); } } } void dfs(int v) { if (visited[v]) return; visited[v] = true; for (const auto& e : graph[v]) dfs(e.dst); stk.push_back(v); } void rdfs(int v) { if (id[v] >= 0) return; id[v] = groups.size() - 1; groups.back().push_back(v); for (const auto& e : rgraph[v]) rdfs(e.dst); } }; struct TwoSat { int vnum; Graph<> graph; explicit TwoSat(int n) : vnum(n), graph(n * 2) {} // t=1 <=> true int enc(int x, bool t) { return x + (t ? vnum : 0); } // [tx]x V [ty]y void span(int x, bool tx, int y, bool ty) { graph[enc(x, !tx)].emplace_back(enc(x, !tx), enc(y, ty)); graph[enc(y, !ty)].emplace_back(enc(y, !ty), enc(x, tx)); } // if unsatisfiable, return an empty vector std::vector exec() { StronglyConnectedComponents scc(graph); std::vector assign(vnum); for (int x = 0; x < vnum; ++x) { int fid = scc.id[enc(x, false)], tid = scc.id[enc(x, true)]; if (fid == tid) { assign.clear(); break; } else { assign[x] = (fid < tid); } } return assign; } }; void solve() { int n; std::cin >> n; std::vector ss(n), ts(n), us(n); for (auto& s : ss) { std::cin >> s; --s; } for (auto& t : ts) { std::cin >> t; --t; } for (auto& u : us) std::cin >> u; TwoSat sat(n * n); auto enc = [&](int x, int y) { return x * n + y; }; for (int i = 0; i < n; ++i) { int p = us[i] & 1, q = us[i] >> 1; for (int j = 0; j < n; ++j) { sat.span(enc(ss[i], j), 1 - p, enc(j, ts[i]), 1 - q); } } auto ans = sat.exec(); if (ans.empty()) { std::cout << -1 << "\n"; } else { for (int x = 0; x < n; ++x) { for (int y = 0; y < n; ++y) { std::cout << ans[enc(x, y)] << " "; } std::cout << "\n"; } } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }