eolymp
bolt
Try our new interface for solving problems
Problems

Star Routes

Star Routes

\includegraphics{https://static.e-olymp.com/content/a9/a91a6884c2324ed21ea0e8466fb4f3202cebac2e.jpg} Space travelers found information about routes between star gates. Using the gates it is possible to get to another world through space hypertunnels. The routes between gates, that are existing in different worlds, represented by matrices. All gates have numbers (\textbf{1} ≤ \textbf{i} ≤ \textbf{100}). Route matrix has \textbf{1} (one) in (\textbf{i},\textbf{j})position, if there is direct route from gate (\textbf{i}) to gate (\textbf{j}). All other positions contain \textbf{0} (zero). Existence of the direct route from gate (\textbf{i}) to gate (\textbf{j}) does not guarantee existence of such route from (\textbf{j}) to (\textbf{i}). But there is always \textbf{1} in (\textbf{i},\textbf{i}) position. The problem is in following. Using given route matrices you have to find advanced route matrix, that shows all possible routes. This matrix can give information whether gate (\textbf{k}) is reachable from any other gate (\textbf{i}). That is if route from gate (\textbf{i}) to gate (\textbf{j}) exists and route from gate (\textbf{j}) to gate (\textbf{k})exists, then route from (\textbf{i}) to (\textbf{k}) exists too. An existence of route is also represented by \textbf{1} in appropriate matrix position. So advanced route can be not only direct but can contain intermediate gates. \InputFile The first line contains matrix dimension \textbf{M} (\textbf{M} ≤ \textbf{100}), next lines contain matrix rows. The elements in rows are separated by one space. Input data are correct. \OutputFile The output is advanced route matrix, one row per line, elements are separated by one space.
Time limit 0.1 seconds
Memory limit 64 MiB
Input example #1
3
1 1 0
0 1 0
1 0 1
Output example #1
1 1 0
0 1 0
1 1 1