P27263 [AtCoder] Reachability
普及+
题目描述

Problem Description

Takahashi received a directed graph with $3N$ vertices from Aoki. The vertices of this graph are named $x_0, x_1, \cdots, x_{N-1}, y_0, y_1, \cdots, y_{N-1}, z_0, z_1, \cdots, z_{N-1}$. All edges in this graph are either from vertices $x$ to vertices $y$ or from vertices $y$ to vertices $z$. There are no duplicate edges.

While playing with this graph, Takahashi obtained $2N$ strings of length $N$, $A_0, A_1, \cdots, A_{N-1}, B_0, B_1, \cdots, B_{N-1}$. These strings have the following properties:

  • The $j$-th character of $A_i$ ($0 \leq i, j \leq N-1$) is 1 if there is an edge from vertex $x_i$ to vertex $y_j$, and 0 otherwise.
  • The $j$-th character of $B_i$ ($0 \leq i, j \leq N-1$) is 1 if there is a path from vertex $x_i$ to vertex $z_j$, and 0 otherwise.

Takahashi accidentally broke the graph but remembers the $2N$ strings. Please show one possible original graph for him. If there is no possible original graph due to incorrect memory, indicate that.

Input Format

The input is given from the standard input in the following format:

$ N $ $ A_0 $ $ A_1 $ $\vdots$ $ A_{N-1} $ $ B_0 $ $ B_1 $ $\vdots$ $ B_{N-1} $

Output Format

If there is no possible original graph, output -1.

If there is a possible original graph, output the edges from vertices $y$ to vertices $z$ in the following format:

$c_{0,0}c_{0,1}\cdots\ c_{0,N-1}$ $c_{1,0}c_{1,1}\cdots\ c_{1,N-1}$ $\vdots$ $c_{N-1,0}c_{N-1,1}\cdots\ c_{N-1,N-1}$

Here, $ c_{i,j} $ is 1 if there is an edge from $ y_i $ to $ z_j $, and 0 otherwise.

If multiple solutions exist, any one of them will be considered correct.

Sample Input and Output

Sample Input #1

3
010
001
101
110
010
011

Sample Output #1

011
110
010

Sample Input #2

3
010
001
101
110
010
001

Sample Output #2

-1

Notes/Hints

Constraints

  • $1 \leq N \leq 300$
  • $ A_i $ is a string of length $ N $ consisting of 0 and 1.
  • $ B_i $ is a string of length $ N $ consisting of 0 and 1.

Sample Explanation 1

For example, according to Takahashi's memory, there is a path from vertex $ x_2 $ to vertex $ z_1 $. In the output graph, there is a path $x_2 \rightarrow y_2 \rightarrow z_1$.

Sample Explanation 2

There is no possible original graph.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 010 001 101 110 010 011
样例输出
011 110 010