Write a program to compute the transitive closure of a directed graph with vertices. That is, you must compute an matrix where at the -th column of the -th row there is a 1 if it is possible to go from to , and there is a 0 otherwise.
Input consists of several cases. Every case begins with followed by the number of arcs . Follow pairs to indicate an arc from to , with . Assume , that the vertices are numbered between 0 and , and that there are no repeated arcs.
For every graph, print its transitive closure, followed by a line with 20 dashes.
In the “large” private test cases, we have .
Input
2 1 0 1 1 0 4 5 1 0 2 3 3 1 2 1 3 0
Output
1 1 0 1 -------------------- 1 -------------------- 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 1 --------------------